Improve PHP-CS-Fixer config sharing, require PHP 8.4, and slim PHP_CodeSniffer#38
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related changes around the PHP-CS-Fixer / PHP_CodeSniffer relationship:
PHP-CS-Fixer config
@PHP8x4Migration,@PHP8x4Migration:risky,@PHPUnit10x0Migration:risky. Renovate already bumps PHP-CS-Fixer, so new migration rules arrive for free.numeric_literal_separator(override_existing: false).ConfigandRulesas@api.tests/PhpCsFixer/RulesTest.php(was zero coverage for the fixer config).PHP 8.4
composer.json:php^8.3->^8.4.test.yml: drop8.3from the matrix (kept8.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.
PSR12ref 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.single_quote,native_function_casing, AND/OR operators,==vs===, member var scope, annotation-aware unused imports, const/property spacing, andGeneric.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.phpcs -econfirms the removed sniffs are gone and the kept ones remain.