- How do I install and configure this PHPCS ruleset for Laravel?
- Run `composer require --dev onramplab/onr-phpcs-laravel` to install. Configure it in your `phpcs.xml` by adding `<rule ref="onr-phpcs-laravel"/>` and specifying directories like `app/`, `routes/`, or `tests/`. Verify installation with `php vendor/bin/phpcs -i`.
- Does this package work with Laravel 8, 9, or 10?
- Yes, it supports Laravel 8+ and aligns with PSR-12, which is framework-agnostic. Tested for compatibility with Laravel’s latest conventions, including Blade templates and Eloquent models. Always pin to a stable PHPCS version in `composer.json`.
- Can I use this alongside Laravel Pint or PHPStan?
- Absolutely. This ruleset enforces linting standards, while Pint auto-fixes code and PHPStan performs static analysis. Run PHPCS in CI/CD to catch violations early, then use Pint locally for quick fixes. Example workflow: PHPCS → Pint → PHPStan.
- How do I exclude specific files or directories from linting?
- Use the `<exclude>` tag in your `phpcs.xml` to skip files or folders. For example, `<exclude name="app/Exceptions/Handler.php"/>` or `<exclude-pattern>*/legacy/*.php</exclude-pattern>`. This is useful for third-party or legacy code.
- Will this break my existing PHPCS configuration?
- Unlikely, but test thoroughly. Run `php vendor/bin/phpcs --standard=onr-phpcs-laravel --report=full app/` to identify conflicts. Merge rulesets if needed, or use the `--strict` flag to enforce new standards incrementally.
- How can I customize the ruleset for my team’s needs?
- Extend the ruleset by creating a custom `phpcs.xml` that overrides specific rules. For example, `<rule ref="onr-phpcs-laravel"> <arg name="severity" value="5" /> <exclude name="Generic.Files.LineLength.TooLong" /> </rule>`. Fork the package if heavy customization is needed.
- Should I run this in CI/CD, and how do I fail builds on violations?
- Yes, add it to your CI pipeline (e.g., GitHub Actions) with a step like `php vendor/bin/phpcs --standard=onr-phpcs-laravel --warning-severity=3 --error-severity=5`. Configure branch protection rules to block merges on errors. Pair with `phpcs --report=emacs` for actionable feedback.
- Does this support parallel linting for large Laravel projects?
- Yes, use tools like `php-parallel-lint` alongside PHPCS to speed up linting. Example: `php-parallel-lint app/ | xargs php vendor/bin/phpcs --standard=onr-phpcs-laravel`. Cache results in CI with `phpcs --cache` to reduce runtime.
- What’s the difference between this and the official `laravel` PHPCS standard?
- This package builds on the `@emielmolenaar/phpcs-laravel` ruleset with opinionated Laravel-specific tweaks (e.g., stricter Blade template rules, naming conventions). It’s more opinionated than the vanilla `laravel` standard but avoids vendor lock-in. Audit both to compare.
- How do I handle false positives or legacy code exceptions?
- Document exceptions in `phpcs.xml` using `<exclude>` or `<arg>` tags. For example, `<arg name="ignore" value="app/old-code/" />`. Use `@phpcs:ignore` docblock annotations for one-off cases. Example: `// @phpcs:ignore Generic.Files.LineLength.TooLong`.