Skip to content

Commit 8e47f87

Browse files
author
Jordi de la Mano
committed
Fixes & refactor
1 parent b239035 commit 8e47f87

19 files changed

+4431
-978
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
vendor/
33
.phpunit.cache
44
.phpcs-cache
5+
build/
6+
composer.lock

.php-cs-fixer.dist.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of Angelov phpunit-vcr.
7+
*
8+
* (c) Angelov <https://angelovdejan.me>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
use Angelov\PHPUnitPHPVcr\Tests\Nexus\CodingStandard;
15+
use Nexus\CsConfig\Factory;
16+
use PhpCsFixer\Finder;
17+
18+
$finder = Finder::create()
19+
->files()
20+
->in([
21+
__DIR__ . '/src/',
22+
__DIR__ . '/tests/',
23+
])
24+
->exclude('build')
25+
->append([
26+
__FILE__,
27+
__DIR__ . '/rector.php',
28+
]);
29+
30+
$overrides = [
31+
'declare_strict_types' => true,
32+
'void_return' => true,
33+
];
34+
35+
$options = [
36+
'finder' => $finder,
37+
'cacheFile' => 'build/.php-cs-fixer.cache',
38+
];
39+
40+
return Factory::create(new CodingStandard(), $overrides, $options)->forLibrary(
41+
'Angelov phpunit-vcr',
42+
'Angelov',
43+
'https://angelovdejan.me',
44+
);

admin/pre-commit

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
3+
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
4+
STAGED_PHP_FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php$`
5+
6+
echo "Starting CodeIgniter precommit..."
7+
8+
if [ "$STAGED_PHP_FILES" != "" ]; then
9+
echo "Linting PHP code..."
10+
for FILE in $STAGED_PHP_FILES; do
11+
php -l -d display_errors=0 "$PROJECT/$FILE"
12+
13+
if [ $? != 0 ]; then
14+
echo "Fix the error(s) before commit."
15+
exit 1
16+
fi
17+
18+
FILES="$FILES $FILE"
19+
done
20+
fi
21+
22+
if [ "$FILES" != "" ]; then
23+
echo "Running PHP CS Fixer..."
24+
25+
if [ -d /proc/cygdrive ]; then
26+
./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
27+
else
28+
php ./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
29+
fi
30+
31+
if [ $? != 0 ]; then
32+
echo "Some files are not following the coding standards. Please fix them before commit (try 'composer style')."
33+
exit 1
34+
fi
35+
fi
36+
37+
exit $?

admin/setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# Install a pre-commit hook that
4+
# automatically runs phpcs to fix styles
5+
cp admin/pre-commit .git/hooks/pre-commit
6+
chmod +x .git/hooks/pre-commit

composer.json

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
{
88
"name": "Dejan Angelov",
99
"homepage": "https://angelovdejan.me"
10+
},
11+
{
12+
"name": "Daycry",
13+
"homepage": "https://daycryweb.blogspot.com"
1014
}
1115
],
1216
"require": {
@@ -16,7 +20,14 @@
1620
"require-dev": {
1721
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0",
1822
"squizlabs/php_codesniffer": "^3.7",
19-
"phpstan/phpstan": "^2.0"
23+
"phpstan/phpstan": "^2.0",
24+
"friendsofphp/php-cs-fixer": "^3.49",
25+
"nexusphp/cs-config": "^3.21",
26+
"phpstan/extension-installer": "^1.3",
27+
"phpstan/phpstan-deprecation-rules": "^2.0",
28+
"phpstan/phpstan-phpunit": "^2.0",
29+
"phpstan/phpstan-strict-rules": "^2.0",
30+
"rector/rector": "^2"
2031
},
2132
"autoload": {
2233
"psr-4": {
@@ -27,5 +38,37 @@
2738
"psr-4": {
2839
"Angelov\\PHPUnitPHPVcr\\Tests\\": "tests/"
2940
}
30-
}
41+
},
42+
"config": {
43+
"optimize-autoloader": true,
44+
"preferred-install": "dist",
45+
"sort-packages": true,
46+
"allow-plugins": {
47+
"phpstan/extension-installer": true
48+
}
49+
},
50+
"scripts": {
51+
"post-update-cmd": [
52+
"bash admin/setup.sh"
53+
],
54+
"analyze": [
55+
"Composer\\Config::disableProcessTimeout",
56+
"phpstan analyze",
57+
"rector process --dry-run"
58+
],
59+
"ci": [
60+
"Composer\\Config::disableProcessTimeout",
61+
"@cs",
62+
"@test"
63+
],
64+
"cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff",
65+
"cs-fix": "php-cs-fixer fix --ansi --verbose --diff",
66+
"mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit",
67+
"sa": "@analyze",
68+
"style": "@cs-fix",
69+
"test": [
70+
"Composer\\Config::disableProcessTimeout",
71+
"vendor/bin/phpunit"
72+
]
73+
}
3174
}

0 commit comments

Comments
 (0)