- What is PHPCSExtra and how does it work with PHP_CodeSniffer?
- PHPCSExtra is a Composer package that registers three extra coding standards, Modernize, NormalizedArrays, and Universal, with PHP_CodeSniffer. It does not run in production; it adds sniffs and fixers you invoke through phpcs or phpcbf in local development or CI. It also depends on PHPCSUtils for shared helper logic. Use it to extend the standards PHPCS bundles, such as PSR-12 or Generic.
- How do I install PHPCSExtra in a Laravel project?
- Add it as a dev dependency with composer require --dev phpcsstandards/phpcsextra. Installation relies on dealerdirect/phpcodesniffer-composer-installer, so make sure that plugin is allowed in config.allow-plugins or registration will not happen in locked-down CI images. Then reference the standards in your ruleset.xml or use them directly with phpcs --standard=Modernize.
- Which PHP and PHP_CodeSniffer versions does PHPCSExtra support?
- Minimum requirements are PHP 5.4 or higher and PHP_CodeSniffer 3.13.6 or 4.x, plus PHPCSUtils 1.2.3 or later. The README also recommends removing direct pins on PHPCS and PHPCSUtils from your root composer.json and letting the standards manage those versions. Tested PHP versions span 5.4 through 8.5.
- Should I use the Universal standard as-is?
- No. Universal is explicitly a sniff collection rather than a coherent standard, and it includes mutually contradictory rules such as Classes.DisallowFinalClass versus Classes.RequireFinalClass. Adopting it wholesale will produce conflicting violations. Instead, select a documented policy subset that fits your project and reference only those sniffs in your ruleset.
- Can PHPCSExtra replace Laravel Pint?
- Not really. Pint is built on PHP-CS-Fixer and handles formatting and style, while PHPCSExtra adds semantic and modernization sniffs on top of PHP_CodeSniffer. Running both without a clear split causes fixer ping-pong and review churn. A common approach is letting Pint own formatting while using selected PHPCSExtra sniffs for correctness checks.
- Which PHPCSExtra sniffs conflict with Laravel or Pint conventions?
- Universal.Arrays.DisallowShort ArraySyntax conflicts directly with idiomatic Laravel and Pint output, which favors short arrays. NormalizedArrays also overlaps with array formatting that Pint already enforces. Enabling these without a decision creates noise that developers learn to ignore. Review the rules against your existing style before turning them on.
- Are PHPCSExtra fixers safe to run automatically?
- Some are, but risky fixers need human review. The maintainers flag Universal.Classes.RequireFinalClass as potentially behavior-changing because auto-fixing it across a codebase can silently break mocking or proxying patterns. Run risky fixes as single-purpose, reviewed commits rather than a bulk phpcbf pass. Safer modernization fixers, such as dirname(__FILE__) to __DIR__, are lower risk.
- How does PHPCSExtra handle different PHP versions?
- Several sniffs honor a php_version runtime setting, so you can tune rules to your project's minimum supported PHP rather than the newest local PHP. That lets modernization sniffs propose changes only where your deployment target supports them. Set php_version in your ruleset config to match your composer.json platform or CI matrix.
- What are the licensing or production concerns with PHPCSExtra?
- PHPCSExtra is LGPL-3.0 licensed. As a dev-only, non-distributed tool, that is generally fine, but get a legal or policy check before adding it to a monorepo template or anywhere dev dependencies are vendored or images redistributed. There is no runtime code path in production, so its value depends entirely on CI enforcement and developer habit.
- How do I keep PHPCSExtra updates from breaking CI?
- Because version resolution for PHPCS and PHPCSUtils is delegated to the standards, a composer update can shift those versions and break CI on an unrelated pull request. Follow the README advice to avoid direct root pins, but pin PHPCSExtra itself to a tested version range and lock dependencies in CI. Run the ruleset in a dedicated job so failures are clearly attributable.