phpcsstandards/phpcsextra
PHPCSExtra is a collection of extra sniffs and coding standards for PHP_CodeSniffer, including Modernize, NormalizedArrays, and Universal rules to help enforce consistent, modern PHP code. Requires PHP 5.4+ and PHPCS 3.13.6/4.x.
Modernize ruleset directly supports a migration initiative (e.g., a PHP 8.x upgrade or "modern PHP" push): it auto-fixes dirname(__FILE__) → __DIR__, collapses nested dirname() calls, and — when a php_version is configured — only flags changes valid for the target version. This turns a modernization epic into a measurable, incremental, CI-enforced workstream rather than a one-off refactor.NormalizedArrays, attribute bracket/parentheses spacing, modifier keyword order, trailing commas) remove stylistic nitpicks from PR review, shifting reviewer attention to design and correctness. Track this as a leading indicator: violations per PR, review comments per PR, and time-to-merge before/after adoption.composer.json) is the cheapest mechanism for making dozens of Laravel/PHP services look and behave the same, and it's enforceable and auditable in a way that a written style guide is not.DuplicateArrayKey, MixedArrayKeyTypes, MixedKeyedUnkeyedArray, ForeachUniqueAssignment, NoEchoSprintf, and ConstructorDestructorReturn catch real bug classes pre-merge. Each is a candidate to enable behind a violation-count baseline, so you can sequence rollout by ROI instead of adopting everything at once.--report=info metrics per sniff give you a quantified inventory of modernization and consistency debt per repository — useful input when sequencing cleanup work against feature work, and a defensible "we reduced X violations by Y%" narrative for quarterly reviews.Consider it when:
php_version.Look elsewhere / proceed with caution when:
Universal is explicitly not a standard and contains contradictory sniffs by design. Using it wholesale will produce conflicting findings; it must be cherry-picked sniff-by-sniff, which is curation work someone must own.Universal.Classes.RequireFinalClass is flagged as a risky fixer with potential runtime side effects; it must never run unattended on application code. Similarly, ForeachUniqueAssignment's fixer preserves existing (possibly unintended) behavior. Gate these behind human review.For executives (one paragraph): This is a free, LGPL-licensed developer tool that plugs into our existing code-quality checks and automatically enforces modern PHP practices and consistent code formatting. It carries zero production risk — it's a dev-only Composer dependency, never shipped in the application — and its blast radius is limited to CI and developer machines. The value is straightforward: less reviewer time spent on style, fewer mechanical defects reaching QA, and a measurable dashboard for our PHP modernization effort. Cost is a few days of one engineer's time to curate the rule set and wire it into CI; ongoing cost is a version bump.
For engineering leadership:
Modernize, NormalizedArrays, and Universal — that layer onto the standards we already run. We adopt incrementally, sniff by sniff, and can back any of it out with a one-line composer.json change.php_version once and the sniffs only flag changes valid for our target runtime, so adoption is compatible with a phased upgrade rather than blocked on it.phpcbf fixers, so remediation cost is largely automated — with a documented exception list for risky fixers we will review manually.require-dev dependency via Composer; pin the version; add a phpcs step to CI and a phpcbf step to pre-commit; publish a short ruleset-rationale doc so developers know why each sniff is on.Universal must be cherry-picked and contains mutually exclusive rules. RequireFinalClass is a risky fixer. The project is community-maintained with a small downstream base, so we own the curation and pinning discipline; forking is a fallback, not a plan. And if we intend to standardize on Laravel Pint, we should have a deliberate conversation about running two linting engines rather than letting both creep in.Ask: Approve a time-boxed pilot — one engineer, two sprints — to curate a ruleset on the two highest-churn repositories, with success measured by (1) reduction in style-related review comments, (2) a documented violation baseline that trends down, and (3) no CI regressions.
How can I help you explore Laravel packages today?