From 46f250054c76b3c6df4e9e8da48456eeab8933ab Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:06:53 +0100 Subject: [PATCH] chore: replace PHP_CodeSniffer with PHP-CS-Fixer --- .gitattributes | 2 +- .github/workflows/ci.yml | 6 +++--- .gitignore | 1 + .php-cs-fixer.php | 35 +++++++++++++++++++++++++++++++++++ AGENTS.md | 11 +++++------ composer.json | 8 ++++---- phpcs.xml.dist | 33 --------------------------------- 7 files changed, 49 insertions(+), 47 deletions(-) create mode 100644 .php-cs-fixer.php delete mode 100755 phpcs.xml.dist diff --git a/.gitattributes b/.gitattributes index e90d998..8be0877 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/phpcs.xml.dist export-ignore +/.php-cs-fixer.php export-ignore /psalm.xml.dist export-ignore /README.md export-ignore /.github export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04f2e80..8e285bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,7 +54,7 @@ jobs: - name: Run Psalm run: vendor/bin/psalm --output-format=github --shepherd - phpcs: + php-cs-fixer: name: Code style runs-on: ubuntu-latest steps: @@ -91,8 +91,8 @@ jobs: env: COMPOSER_ROOT_VERSION: dev-master - - name: Run PHPCodeSniffer - run: vendor/bin/phpcs --report=checkstyle -q --parallel=1 | cs2pr + - name: Run PHP-CS-Fixer + run: vendor/bin/php-cs-fixer check --format=checkstyle | cs2pr test-static-analysis: name: Run static analysis on the tests themselves diff --git a/.gitignore b/.gitignore index b3bc157..5fe65b3 100755 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock vendor .claude/settings.local.json +/.php-cs-fixer.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..3757f04 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,35 @@ +setUnsupportedPhpVersionAllowed(true) + ->setRiskyAllowed(false) + ->setRules([ + '@PER-CS3x0' => true, + // import + 'global_namespace_import' => [ + 'import_classes' => false, + 'import_constants' => false, + 'import_functions' => false, + ], + 'no_unused_imports' => true, + 'ordered_imports' => true, + ]) + ->setFinder( + (new Finder()) + ->in([ + __DIR__ . '/src', + __DIR__ . '/tools/behat', + ]) + ->name('*.php') + ->exclude(['vendor', 'run']) + ->append([ + __FILE__, + ]), + ) + ->setParallelConfig(ParallelConfigFactory::detect()); diff --git a/AGENTS.md b/AGENTS.md index 489306f..2eafdef 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,7 +56,7 @@ These come first, before every other rule here: CI (`.github/workflows/ci.yml`) is the source of truth: - `psalm` (PHP 8.2): `COMPOSER_ROOT_VERSION=dev-master composer update --prefer-dist`, then `vendor/bin/psalm --output-format=github --shepherd` on `src/`. -- `phpcs`: `vendor/bin/phpcs`. `composer check` runs phpcs and Psalm. +- `php-cs-fixer`: `vendor/bin/php-cs-fixer check --diff`. `composer check` runs PHP-CS-Fixer and Psalm. - `test-static-analysis` (PHP 8.2): `cd tools/behat && composer install && vendor/bin/psalm`, then `php tools/behat/lint-features.php` (see "Tests"). - `tests`: deps high/low/stable × PHP 8.2 and 8.4 on pull requests, PHP 8.2 to 8.4 on pushes, @@ -83,8 +83,8 @@ Locally: nothing ("No scenarios"). Check that the output says `1 scenario`. - The full suite (a few minutes) at most once, right before pushing. Never between iterations, and never sweeps (re-running batches of scenarios, looping over fixtures). -- `vendor/bin/phpcs -q`, `vendor/bin/psalm --no-cache` (~2 s) and `php tools/behat/lint-features.php` are cheap - and fine at any time. +- `vendor/bin/php-cs-fixer check`, `vendor/bin/psalm --no-cache` (~2 s) and + `php tools/behat/lint-features.php` are cheap and fine at any time. - Also fine: a scratch-project repro (skill `plugin-repro`). - When briefing a subagent, spell all of this out ("single scenarios only, no full suite, no sweeps"); a vague "don't run the tests" is not enough. @@ -209,9 +209,8 @@ workaround explicitly in the report. ## Code style -- phpcs (`phpcs.xml.dist`): PSR12, short arrays, 120-character absolute line limit, applied - to `src/`. Run `vendor/bin/phpcs` - (`vendor/bin/phpcbf` fixes). +- PHP-CS-Fixer (`.php-cs-fixer.php`): PER-CS 3.0, applied to `src/` and `tools/behat/`. Run + `vendor/bin/php-cs-fixer check --diff` (`vendor/bin/php-cs-fixer fix` fixes). - Match the surrounding code: comment density, naming, idiom. - Comments are concise and only explain what isn't obvious from the code: - don't restate the code in prose; diff --git a/composer.json b/composer.json index b81a30e..dc93fcb 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ "vimeo/psalm": "^7.2 || dev-master" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.88", "phpspec/prophecy-phpunit": "^2.5", - "phpunit/phpunit": "^11.0 || ^12.0 || ^13.0", - "squizlabs/php_codesniffer": "^3.13" + "phpunit/phpunit": "^11.0 || ^12.0 || ^13.0" }, "conflict": { "phpspec/prophecy": "<1.20.0", @@ -48,7 +48,7 @@ "@cs-check", "@analyze" ], - "cs-check": "phpcs", - "cs-fix": "phpcbf" + "cs-check": "php-cs-fixer check --diff", + "cs-fix": "php-cs-fixer fix" } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100755 index e935b5b..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - src - - - - - - - - - - - - - - - - - - - - -