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.
composer require --dev), requiring only a phpcs.xml config.phpcs.xml).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Performance Overhead | Minimal for CI (runs on demand); may slow local dev if overzealous. | Exclude vendor/ and node_modules/ from scans. |
| False Positives | Some sniffs (e.g., docblock checks) may conflict with legacy Laravel code. | Customize phpcs.xml to disable problematic rules (e.g., PSR2.Methods.Underscore). |
| Breakage on Upgrades | New PHP versions may introduce stricter rules. | Test in a staging environment; use --dry-run before enforcing. |
| IDE Integration | Tokenizer tool (vendor/bin/tokenize) may confuse non-technical devs. |
Document usage clearly; provide IDE-specific guides (PHPStorm/VSCode). |
| Maintenance Burden | Requires updates if PHP_CodeSniffer or PSR-2-R evolves. | Monitor fig-r/psr2r-sniffer for breaking changes; pin versions in composer.json. |
phpcs (e.g., squizlabs/PHP_CodeSniffer) or run alongside it?phpcbf) in PRs vs. manual fixes?laravel-shift/coding-standard)?| Component | Version Requirement | Laravel Compatibility |
|---|---|---|
| PHP | ≥8.1 | Laravel 9+ (LTS) |
| Laravel | Any (no core changes) | Full |
| PHP_CodeSniffer | v4+ (bundled dependency) | Automatic |
| Composer | ≥2.0 | Required |
| IDEs (PHPStorm/VSCode) | Plugin support | Full (via external tools) |
phpcs --report=summary.composer.json (require-dev).phpcs.xml with lenient rules (e.g., severity=5 for warnings).phpcbf) in CI for fixable issues.husky or pre-commit).phpcs.xml to override conflicting rules (e.g., disable PSR2.Methods.Underscore if Laravel uses snake_case).<rule ref="PSR2.Methods.Underscore">
<severity>0</severity> <!-- Disable -->
</rule>
.github/workflows/ci.yml:
- name: PSR-2-R Sniffer
run: vendor/bin/phpcs --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --warning-severity=5
package.json (for Node-based projects):
"scripts": {
"lint:php": "php vendor/bin/phpcs src/ tests/"
}
simple-php-unit-tester).Ctrl+Comma sniffs.phpcbf to CI for auto-correctable issues:
- name: Auto-Fix PSR-2-R
run: vendor/bin/phpcbf src/ tests/
fig-r/psr2r-sniffer to a minor version (e.g., ^2.7) to avoid breaking changes.squizlabs/PHP_CodeSniffer for major updates (e.g., v4 → v5).phpcs.xml template for onboarding new devs.CONTRIBUTING.md snippet explaining:
How can I help you explore Laravel packages today?