Skip to content

Improve PHP-CS-Fixer config sharing, require PHP 8.4, and slim PHP_CodeSniffer#38

Merged
alies-dev merged 3 commits into
1.xfrom
improve-php-cs-fixer-sharing
Jun 25, 2026
Merged

Improve PHP-CS-Fixer config sharing, require PHP 8.4, and slim PHP_CodeSniffer#38
alies-dev merged 3 commits into
1.xfrom
improve-php-cs-fixer-sharing

Conversation

@alies-dev

@alies-dev alies-dev commented Jun 25, 2026

Copy link
Copy Markdown
Member

Summary

Two related changes around the PHP-CS-Fixer / PHP_CodeSniffer relationship:

  1. Harden and extend the shared PHP-CS-Fixer config; bump the package to PHP 8.4.
  2. Make PHP-CS-Fixer the primary tool (it owns formatting) and slim PHP_CodeSniffer down to the structural/semantic checks the fixer cannot do, removing duplicated formatting sniffs.

PHP-CS-Fixer config

  • Add migration rulesets for automatic modernization: @PHP8x4Migration, @PHP8x4Migration:risky, @PHPUnit10x0Migration:risky. Renovate already bumps PHP-CS-Fixer, so new migration rules arrive for free.
  • Add numeric_literal_separator (override_existing: false).
  • Mark Config and Rules as @api.
  • Fix the stale raw-require example in the rules-file docblock.
  • Add tests/PhpCsFixer/RulesTest.php (was zero coverage for the fixer config).

PHP 8.4

  • composer.json: php ^8.3 -> ^8.4.
  • test.yml: drop 8.3 from the matrix (kept 8.4, 8.5).

PHP_CodeSniffer dedup

PHP_CodeSniffer no longer checks what PHP-CS-Fixer already fixes (the fixer is faster and auto-fixes). Removals were mapped against the expanded 151-rule effective fixer set, not by name alone.

  • Removed ~30 standalone sniffs with an exact fixer equivalent (array syntax/indentation, cast and operator spacing, trailing commas, yoda style, null coalesce, short list, import ordering, etc.).
  • Replaced the whole PSR12 ref with the three PSR1 sniffs the fixer cannot enforce (PSR1.Files.SideEffects, PSR1.Classes.ClassDeclaration, PSR1.Methods.CamelCapsMethodName), since @PER-CS3x0 (PER-CS supersedes PSR-12) covers all PSR12 formatting.
  • Net active sniffs: 228 -> 152.
  • Kept sniffs with no fixer equivalent in our config: single_quote, native_function_casing, AND/OR operators, == vs ===, member var scope, annotation-aware unused imports, const/property spacing, and Generic.CodeAnalysis.EmptyStatement (empty control-structure bodies, distinct from stray semicolons).

Consumer impact

PHP_CodeSniffer is now supplementary, not a standalone standard: projects should run both tools (formatting comes from PHP-CS-Fixer). README updated to state this.

Verification

  • vendor/bin/phpunit: 18 passing.
  • PHP-CS-Fixer dry-run with the real ruleset resolves with no rule conflicts.
  • Fixer fixtures confirm it catches the formatting concerns of the removed sniffs (scope indent, scalar casts, superfluous whitespace, PSR12 brace/spacing/switch/new-parens).
  • phpcs -e confirms the removed sniffs are gone and the kept ones remain.

- Add @PHP8x4Migration, @PHP8x4Migration:risky and @PHPUnit10x0Migration:risky
  rulesets for automatic syntax/test modernization, plus numeric_literal_separator.
- Mark Config and Rules as @api to declare the supported BC surface.
- Add a smoke test covering Rules::get() and Config::create().
- Fix the stale raw-require path example in the rules file docblock.
- Bump required PHP to ^8.4 and drop 8.3 from the CI matrix.
- Restructure README: PHP-CS-Fixer first, then PHP_CodeSniffer, for clarity.
Now that the shared PHP-CS-Fixer config owns formatting, stop checking the
same issues with PHP_CodeSniffer (PHP-CS-Fixer is faster and auto-fixes).

Removed 30 sniffs whose concern is fully handled by an enabled fixer rule
(verified against the expanded 151-rule set), e.g. array syntax/indentation,
cast and operator spacing, trailing commas, yoda style, null coalesce,
short list, import ordering, scope indentation, superfluous whitespace.

Kept sniffs with no fixer equivalent in our config: single_quote,
native_function_casing, AND/OR operators, == vs ===, member var scope,
annotation-aware unused imports, and const/property spacing.

Generic.CodeAnalysis.EmptyStatement is kept: it detects empty control-structure
bodies, not stray semicolons (that is Slevomat UselessSemicolon, which is removed).
PHP-CS-Fixer's @PER-CS3x0 (PER-CS supersedes PSR-12) already enforces every
PSR12 formatting concern, verified against the expanded fixer ruleset. Replace
the whole PSR12 ref with the three PSR1 sniffs PHP-CS-Fixer cannot cover:
side-effect separation, one-symbol-per-file, and method camelCase naming.
Const visibility stays enforced via SlevomatCodingStandard.Classes.ClassConstantVisibility.

README now states PHP-CS-Fixer is primary (owns formatting) and PHP_CodeSniffer
is supplementary, not a complete standard on its own.
@alies-dev alies-dev changed the title Improve PHP-CS-Fixer config sharing and require PHP 8.4 Improve PHP-CS-Fixer config sharing, require PHP 8.4, and slim PHP_CodeSniffer Jun 25, 2026
@alies-dev alies-dev self-assigned this Jun 25, 2026
@alies-dev alies-dev changed the base branch from main to 1.x June 25, 2026 09:53
@alies-dev alies-dev merged commit ef2e977 into 1.x Jun 25, 2026
5 checks passed
@alies-dev alies-dev deleted the improve-php-cs-fixer-sharing branch June 25, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant