feat: add PHP_CodeSniffer 4.x support - #724
Open
MickaelN wants to merge 1 commit into
Open
Conversation
Upgrade squizlabs/php_codesniffer from ^3.13.5 to ^4.0 and slevomat/coding-standard from ^8.22.1 to ^8.23. Changes: - File.php: typed addMessage() signature, fixableCount replaced by fixableErrorCount/fixableWarningCount - SniffDecorator.php: typed process() parameter - ForbiddenSetterSniff.php: typed process() parameter, dotted error code to comply with PHPCS 4 naming validation, getDeclarationName empty string check - Metrics: removed CodeAnalyzerSniff (dropped from Zend in PHPCS 4, redundant with SyntaxCheck), removed CallTimePassByReferenceSniff (dropped, irrelevant since PHP 5.4), moved LanguageConstructSpacingSniff from Squiz to Generic namespace - TestCase: manual sniff registration to bypass PHPCS 4 namespace convention validation for custom sniffs Closes nunomaduro#723
MickaelN
force-pushed
the
feat/phpcs-4-support
branch
from
August 25, 2026 15:48
bf35750 to
5aaef9c
Compare
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
Adds support for
squizlabs/php_codesniffer4.x, bumping it from^3.13.5to^4.0andslevomat/coding-standardfrom^8.22.1to^8.23.Closes #723
Rebased on
master, so thecomposer.jsondiff is limited to those two packages — every other constraint is left as it is onmaster.Changes
Core:
File.php:addMessage()now declares native parameter types to match the new parent signature, andfixableCount— removed in PHPCS 4 — is replaced byfixableErrorCount/fixableWarningCount, incremented according to$isErrorSniffDecorator.php: nativeinttype on theprocess()$stackPtrparameter, dropping the now-unnecessary@phpcsSuppressannotationForbiddenSetterSniff.php: same native type onprocess(), error code changed to the dotted formPhpInsights.Sniffs.ForbiddenSetterto satisfy PHPCS 4 code validation, and thegetDeclarationName()null check replaced by an empty-string check — the method's return type went from?stringtostringin PHPCS 4, returning''when the name cannot be determined during live codingRemoved sniffs (dropped in PHPCS 4):
Zend\Debug\CodeAnalyzerSniff— removed upstream without replacement. It shelled out tozend_code_analyzer, a binary that has not shipped for years, and its role is already covered bySyntaxCheckviaparallel-lintGeneric\Functions\CallTimePassByReferenceSniff— removed upstream without replacement. Call-time pass-by-reference has been a fatal error since PHP 5.4, so the sniff cannot fire on any version this package supportsMoved sniff:
Squiz\WhiteSpace\LanguageConstructSpacingSniff→Generic\WhiteSpace\LanguageConstructSpacingSniffTests:
TestCase::prepareFixtureWithSniff(): registers the sniff instance manually. PHPCS 4 validates sniff namespaces inpopulateTokenListeners()against theStandard\Sniffs\Category\SniffNameconvention, which this package's custom sniffs do not followParamTypeHint,UnorderedUse) updated to stay consistent with what the fixers now produceVerification
Full CI suite green locally on PHP 8.4.17, with PHPCS 4.0.4 and slevomat 8.31.1:
phpstanphp-cs-fixer --dry-runphpunitinsights(self-analysis)Also run against a large Symfony codebase (~1900 files): Code, Complexity and Architecture scores are identical to the PHPCS 3 baseline, Style is within 1.2 points.