fig-r/psr2r-sniffer
PHP_CodeSniffer ruleset implementing PSR-2-R for PHP 8.1+ projects. Includes 190+ sniffs, supports CI, and can auto-fix many issues via phpcbf. Install with Composer and reference the bundled PSR2R ruleset in phpcs.xml.
Install the package as a dev dependency using Composer:
composer require --dev fig-r/psr2r-sniffer
Create a phpcs.xml file in your project root referencing the provided ruleset:
<?xml version="1.0"?>
<ruleset name="PSR-2-R">
<rule ref="vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml"/>
<file>src/</file>
<file>tests/</file>
</ruleset>
Run static analysis on your code:
vendor/bin/phpcs
vendor/bin/phpcbf # Auto-fix where possible
The package is a drop-in extension of PHP_CodeSniffer (PHPCS), so all PHPCS commands and flags (e.g., -v, --ignore, --sniffs) work as expected.
phpcs in pre-commit hooks or CI pipelines (e.g., GitHub Actions, GitLab CI) with phpcs --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml to enforce style rules automatically.phpcs and phpcbf on save via keyboard shortcuts (e.g., Ctrl+. for fix, Ctrl+, for check).phpcs.xml to enable, disable, or configure specific sniffs—especially useful when adopting gradually or accommodating legacy code:
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<severity>0</severity>
</rule>
phpcbf on new code only by using --ignore patterns for legacy directories, then progressively relax exclusions over time.bin/tokenize utility to inspect PHP token streams when developing custom sniffs—critical for understanding node locations, scope conditions, and brace nesting.--sniffs=... with -v to verify whether a violation can be corrected automatically.<severity>0</severity> to disable a sniff, not <exclude>—the latter only suppresses reporting, not execution, and may affect performance unexpectedly.\ instead of / in CLI commands (e.g., vendor\bin\phpcs)—especially in CI scripts.EndFileNewline, PHP DocBlockTagOrder) to prevent destructive corrections during active editing.-vvv for deep token-level insight into why a sniff triggers. This is invaluable when debugging false positives or custom sniff behavior.checkstyle, json), and integrations with static analysis tools like Psalm or PHPStan via CI pipelines.How can I help you explore Laravel packages today?