- How do I install php-collective/code-sniffer for Laravel?
- Add it as a dev dependency with `composer require --dev php-collective/code-sniffer`, then configure `phpcs.xml` to reference `PhpCollective/ruleset.xml`. No Laravel-specific setup is needed beyond standard PHP_CodeSniffer integration.
- Does this package support Laravel’s PSR-2/PSR-12 conventions?
- Yes, it fully adheres to PSR-2 and includes PSR-12 sniffs. It’s designed to complement Laravel’s existing coding standards without conflicts, making it a natural fit for Laravel projects.
- Can I auto-fix code style issues in Laravel?
- Absolutely. Use `phpcbf` (auto-fixer) alongside `phpcs` (sniffer) or run `composer cs-fix` if you’ve set up the Composer script. It supports all the same rules as `phpcs` for auto-correction.
- What’s the difference between PhpCollective and PhpCollectiveStrict?
- PhpCollectiveStrict is a stricter subset of the standard with additional rules (e.g., stricter use statements). Use it for teams needing higher coding discipline, but start with PhpCollective for gradual adoption.
- Will this work with Laravel 9+ and PHP 8.1+?
- Yes, the package requires PHP 8.1+ and is fully compatible with Laravel 9+. Older Laravel versions may need minor adjustments, but no breaking changes are expected for modern setups.
- How do I integrate this with PHPStorm or VSCode?
- Configure an external tool in PHPStorm (e.g., `vendor/bin/phpcs`) or use VSCode’s PHP_CodeSniffer extension. The package provides IDE-friendly rulesets, so real-time linting and fixes work out of the box.
- Can I customize or override rules for Laravel-specific cases?
- Yes, override any rule in `phpcs.xml` (e.g., disable `DocBlockTagOrder` for legacy code). The package supports project-specific sniffs, and Laravel’s class aliases (e.g., `Mockery`) can be whitelisted.
- How does this perform on large Laravel apps (e.g., 10k+ lines)?
- Optimized for speed—scanning 11k-line controllers takes ~6s vs. ~40s with unoptimized setups. Use `--parallel=16` in CI for further speedups, but test locally first to avoid false positives.
- Should I use this alongside PHPStan or PHP-CS-Fixer?
- Yes! Pair it with PHPStan (level 8+) for static analysis and PHP-CS-Fixer for auto-formatting. This package includes `phpcbf` for fixes, but you can run both tools in CI for comprehensive checks.
- What’s the migration path for existing Laravel projects?
- Start by adding the package to `composer.json` and configuring `phpcs.xml`. Run `composer cs-check` in staging to identify violations, then incrementally apply fixes. Use Git hooks or CI to enforce rules pre-merge.