Skip to content

Commit 5a7be63

Browse files
authored
Merge pull request datamweb#8 from datamweb/add-cs-fixer
chore: add the code quality tools of `cs-fixer`
2 parents c070ea1 + eca64e8 commit 5a7be63

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
vendor/
2+
build/
3+
phpunit*.xml
4+
phpunit
5+
*.cache
6+
composer.lock
7+
.DS_Store
8+
.idea/

.php-cs-fixer.dist.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of Shield OAuth.
7+
*
8+
* (c) Datamweb <pooya_parsa_dadashi@yahoo.com>
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 CodeIgniter\CodingStandard\CodeIgniter4;
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([__FILE__]);
26+
27+
$overrides = [
28+
'declare_strict_types' => true,
29+
'void_return' => true,
30+
];
31+
32+
$options = [
33+
'finder' => $finder,
34+
'cacheFile' => '.php-cs-fixer.cache',
35+
];
36+
37+
return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary(
38+
'Shield OAuth',
39+
'Datamweb',
40+
'pooya_parsa_dadashi@yahoo.com'
41+
);

admin/pre-commit

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
if [ "$FILES" != "" ]; then
3+
echo "Running PHP CS Fixer..."
4+
5+
if [ -d /proc/cygdrive ]; then
6+
./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
7+
else
8+
php ./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
9+
fi
10+
11+
if [ $? != 0 ]; then
12+
echo "Some files are not following the coding standards. Please fix them before commit (try 'composer style')."
13+
exit 1
14+
fi
15+
fi
16+
17+
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
}
2121
],
2222
"homepage": "https://github.com/datamweb/shield-oauth",
23+
"minimum-stability": "dev",
24+
"prefer-stable": true,
2325
"require": {
2426
"php": "^7.4.3 || ^8.0 || ^8.1",
2527
"codeigniter4/shield": "dev-develop"
@@ -43,6 +45,18 @@
4345
"Tests\\Support\\": "tests/_support"
4446
}
4547
},
48+
"scripts": {
49+
"post-update-cmd": [
50+
"bash admin/setup.sh"
51+
],
52+
"ci": [
53+
"Composer\\Config::disableProcessTimeout",
54+
"@cs"
55+
],
56+
"cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff",
57+
"cs-fix": "php-cs-fixer fix --ansi --verbose --diff",
58+
"style": "@cs-fix"
59+
},
4660
"support": {
4761
"forum": "https://github.com/datamweb/shield-oauth/discussions",
4862
"source": "https://github.com/datamweb/shield-oauth",

0 commit comments

Comments
 (0)