- Can I use YoastCS for Laravel projects that aren’t WordPress plugins/themes?
- Yes, but selectively. YoastCS includes WordPress-specific sniffs (e.g., `WordPress.WP.GetMetaSingle`), which you can disable in `.phpcs.xml` by excluding the `WordPress` ruleset. The core PHPCS standards (PSR-12, SlevomatCodingStandard) are still valuable for Laravel’s code quality.
- How do I install YoastCS for a Laravel project?
- Run `composer require --dev yoast/yoastcs` in your Laravel project. Ensure `allow-plugins.dealerdirect/phpcodesniffer-composer-installer` is enabled in your `composer.json` or globally. The package auto-registers with PHP_CodeSniffer, so no additional config is needed for basic usage.
- Which Laravel versions does YoastCS support?
- YoastCS is PHP-version agnostic but defaults to PHP 7.4+ rules. Laravel 10+ (PHP 8.1+) works fine—just test with `phpcs --report=full` to check for PHP 8.1+ compatibility issues. Disable `PHPCompatibilityWP` sniffs if targeting non-WordPress Laravel apps.
- How do I configure YoastCS to work with Laravel’s CI (GitHub Actions/GitLab CI)?
- Add a step to your CI pipeline using `phpcs` with the Yoast standard, e.g., `phpcs --standard=Yoast --warning-severity=0 src/`. Set `YOASTCS_THRESHOLD_ERRORS=0` to block merges on errors. For Parallel Lint, use `./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor`.
- Will YoastCS conflict with Laravel’s built-in PSR-12 compliance?
- No, YoastCS extends PSR-12 (via SlevomatCodingStandard) rather than replacing it. Run `phpcs --diff` to compare violations between PSR12 and YoastCS. If conflicts arise, override rules in `.phpcs.xml` (e.g., relax `SlevomatCodingStandard.Arrays.ArrayAccess` for legacy Laravel code).
- How do I exclude Laravel’s `vendor/` or `node_modules/` from YoastCS scans?
- Use the `--exclude` flag with `phpcs` (e.g., `phpcs --standard=Yoast --exclude vendor,node_modules src/`). For Parallel Lint, exclude them via CLI options: `parallel-lint . -e php --exclude vendor,node_modules`. Add these to your `composer.json` scripts for consistency.
- Can I use YoastCS locally in PhpStorm or VSCode?
- Yes. Install the PHP_CodeSniffer plugin for your IDE, then configure it to use the Yoast standard. In PhpStorm: `Settings > Languages & Frameworks > PHP > Code Sniffer > Standard: Yoast`. For VSCode, use the `php-cs-fixer` extension and set the ruleset to YoastCS.
- What’s the performance impact of YoastCS on large Laravel projects?
- Minimal for most projects. Parallel Lint significantly speeds up linting by processing files in parallel. Exclude heavy directories (e.g., `vendor/`) and use `--parallel` with `phpcs` for further optimization. Test with `time phpcs --standard=Yoast src/` to benchmark.
- How do I handle false positives in Laravel-specific code (e.g., Facade usage)?
- Override Yoast’s rules in `.phpcs.xml` to ignore Laravel patterns. For example, disable `WordPress.WP.GetMetaSingle` for non-WordPress projects or relax `SlevomatCodingStandard.ControlStructures.ControlSignature` for Facade methods. Document exceptions in your team’s coding guidelines.
- Are there alternatives to YoastCS for Laravel code quality?
- For pure Laravel projects, consider `squizlabs/php_codesniffer` with PSR12 or `php-cs-fixer` for automated fixes. If targeting WordPress, `WordPress-Coding-Standards/WordPress-Coding-Standards` alone may suffice. YoastCS adds Parallel Lint and Yoast-specific sniffs, which are unique.