- How do I install PSR-2-R Sniffer in a Laravel project?
- Run `composer require --dev fig-r/psr2r-sniffer` in your Laravel project root. No additional Laravel-specific setup is needed beyond adding a `phpcs.xml` file referencing the bundled ruleset.
- Does this package work with Laravel 8.x or older?
- No, PSR-2-R Sniffer requires PHP 8.1+, which aligns with Laravel 9+. For Laravel 8.x, consider alternatives like `php-cs-fixer` with PSR-12 rules or upgrade your Laravel version.
- Can I auto-fix code style issues in Laravel using this package?
- Yes, use `phpcbf` (PHP Code Beauty Fix) to auto-correct supported violations. Run it via `vendor/bin/phpcbf` in your project root or target specific files/directories.
- How do I configure PSR-2-R Sniffer to ignore Laravel-specific code like magic methods?
- Edit your `phpcs.xml` to exclude sniffs conflicting with Laravel’s conventions. For example, exclude `PSR2.Classes.PropertyDeclaration.Underscore` for magic properties or add path exclusions like `<exclude-pattern>app/Providers/*</exclude-pattern>`.
- Will this package slow down my Laravel CI pipeline?
- Running 230+ sniffs may impact performance, especially for large codebases. Mitigate this by excluding non-critical paths (e.g., `vendor/`, `storage/`) or running sniffs in parallel using tools like `php-parallel-lint`.
- How does PSR-2-R Sniffer differ from `pint` or `php-cs-fixer`?
- PSR-2-R Sniffer enforces stricter PSR-2-R rules (including PHP 8.1+ features like enums) and provides granular sniffs, while `pint` is a formatter focused on auto-fixing. Avoid redundancy by disabling overlapping rules in `phpcs.xml` (e.g., whitespace sniffs if `pint` handles them).
- Can I integrate this with Laravel’s Artisan for custom commands?
- Yes, create a custom Artisan command to run sniffs or auto-fixes. Register it in a service provider and call it via `php artisan`. Example: `php artisan psr2r:fix` to auto-correct issues in the `app/` directory.
- How do I handle false positives, like Laravel’s dynamic Facades (e.g., `Route::`)?
- Exclude specific sniffs or paths in `phpcs.xml`. For Facades, disable sniffs like `DocBlockReturnSelfSniff` or use `<exclude-pattern>` to target problematic files. Test with `--sniffs=...` to isolate issues before full adoption.
- Should I use PSR-2-R Sniffer alongside PHPStan or Psalm?
- Yes, but configure them separately. PSR-2-R Sniffer focuses on code style, while static analyzers like PHPStan handle type safety. Run them in CI sequentially or use tools like `parallel-lint` to avoid conflicts.
- How do I migrate from PSR-12 or `php-cs-fixer` to PSR-2-R Sniffer?
- Start by running PSR-2-R Sniffer in a feature branch with a subset of sniffs (e.g., whitespace rules). Use `phpcbf` to auto-fix issues incrementally, then expand to stricter rules. Document the migration path for your team.