From 5f56351f40224f293a75ebfc0ac9c8fcd70a4a34 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 3 Jun 2021 21:15:05 +0800 Subject: [PATCH] Use php-cs-fixer as coding style tool --- .gitattributes | 1 + .github/workflows/test-phpunit.yml | 4 ++-- .gitignore | 2 ++ .php-cs-fixer.dist.php | 34 ++++++++++++++++++++++++++++++ admin/framework/composer.json | 6 +++--- composer.json | 4 ++-- utils/PhpCsFixer/CodeIgniter4.php | 26 +++++++++++++++++++++++ 7 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 .php-cs-fixer.dist.php create mode 100644 utils/PhpCsFixer/CodeIgniter4.php diff --git a/.gitattributes b/.gitattributes index 1a7b3deb77e8..bf0e1f766d96 100644 --- a/.gitattributes +++ b/.gitattributes @@ -25,6 +25,7 @@ utils/ export-ignore rector.php export-ignore phpunit.xml.dist export-ignore phpstan.neon.dist export-ignore +.php-cs-fixer.dist.php export-ignore # The source user guide, either user_guide_src/ export-ignore diff --git a/.github/workflows/test-phpunit.yml b/.github/workflows/test-phpunit.yml index 1b547fb76884..9b9da589720f 100644 --- a/.github/workflows/test-phpunit.yml +++ b/.github/workflows/test-phpunit.yml @@ -122,7 +122,7 @@ jobs: - name: Install dependencies run: | composer update --ansi --no-interaction - composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan codeigniter4/codeigniter4-standard squizlabs/php_codesniffer + composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan friendsofphp/php-cs-fixer nexusphp/cs-config php -r 'file_put_contents("vendor/laminas/laminas-zendframework-bridge/src/autoload.php", "");' env: COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} @@ -140,7 +140,7 @@ jobs: - if: github.repository_owner == 'codeigniter4' && matrix.php-versions == '7.4' name: Run Coveralls run: | - composer global require php-coveralls/php-coveralls:^2.4 + composer global require --ansi php-coveralls/php-coveralls:^2.4 php-coveralls --coverage_clover=build/logs/clover.xml -v env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index b769053b4a4b..74c6d0ce6c4f 100644 --- a/.gitignore +++ b/.gitignore @@ -126,3 +126,5 @@ nb-configuration.xml /results/ /phpunit*.xml /.phpunit.*.cache + +/.php-cs-fixer.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 000000000000..d1680e4c635d --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,34 @@ +files() + ->in([ + __DIR__ . '/app', // @todo relocate when `header_comment` is enabled + __DIR__ . '/public', // @todo relocate when `header_comment` is enabled + __DIR__ . '/system', + __DIR__ . '/tests', + __DIR__ . '/utils', + ]) + ->exclude(['ThirdParty']) + ->notName('#Foobar.php$#') + ->append([ + __FILE__, + __DIR__ . '/rector.php', + __DIR__ . '/spark', + ]); + +$overrides = []; + +$options = [ + 'cacheFile' => 'build/.php-cs-fixer.cache', + 'finder' => $finder, +]; + +// @todo change to `forLibrary()` when `header_comment` is enabled +return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects(); diff --git a/admin/framework/composer.json b/admin/framework/composer.json index e5e88487cfe6..5e226ff38b42 100644 --- a/admin/framework/composer.json +++ b/admin/framework/composer.json @@ -15,12 +15,12 @@ "psr/log": "^1.1" }, "require-dev": { - "codeigniter4/codeigniter4-standard": "^1.0", "fakerphp/faker": "^1.9", + "friendsofphp/php-cs-fixer": "^3.0", "mikey179/vfsstream": "^1.6", + "nexusphp/cs-config": "^3.1", "phpunit/phpunit": "^9.1", - "predis/predis": "^1.1", - "squizlabs/php_codesniffer": "^3.3" + "predis/predis": "^1.1" }, "suggest": { "ext-fileinfo": "Improves mime type detection for files" diff --git a/composer.json b/composer.json index ef2e937e7dce..afefbb7b38fd 100644 --- a/composer.json +++ b/composer.json @@ -15,15 +15,15 @@ "psr/log": "^1.1" }, "require-dev": { - "codeigniter4/codeigniter4-standard": "^1.0", "fakerphp/faker": "^1.9", + "friendsofphp/php-cs-fixer": "^3.0", "mikey179/vfsstream": "^1.6", + "nexusphp/cs-config": "^3.1", "nexusphp/tachycardia": "^1.0", "phpstan/phpstan": "0.12.88", "phpunit/phpunit": "^9.1", "predis/predis": "^1.1", "rector/rector": "0.11.8", - "squizlabs/php_codesniffer": "^3.3", "symplify/package-builder": "^9.3" }, "suggest": { diff --git a/utils/PhpCsFixer/CodeIgniter4.php b/utils/PhpCsFixer/CodeIgniter4.php new file mode 100644 index 000000000000..96b03cd32f8b --- /dev/null +++ b/utils/PhpCsFixer/CodeIgniter4.php @@ -0,0 +1,26 @@ +name = 'CodeIgniter4 Revised Coding Standards'; + + $this->rules = []; + + $this->requiredPHPVersion = 70300; + + $this->autoActivateIsRiskyAllowed = true; + } +}