yoast/yoastcs
Yoast Coding Standards (YoastCS) provides Composer-installable rulesets for PHP_CodeSniffer plus PHP Parallel Lint, bundling Yoast sniffs and selected external standards (including WordPress). Use it to enforce consistent code style and quality in Yoast projects.
yoast/yoastcs as a dev dependency (composer require --dev yoast/yoastcs).Yoast standard (via .phpcs.xml or CLI)..phpcs.xml (e.g., relax SlevomatCodingStandard.Arrays.ArrayAccess for legacy code).WordPress.WP.GetMetaSingle) if irrelevant.| Risk Area | Severity | Mitigation |
|---|---|---|
| PHP Version Mismatch | Medium | YoastCS defaults to PHP 7.4+. Laravel 10+ supports PHP 8.1+. Test with phpcs --report=full. |
| WordPress Dependency | Low | Only PHPCompatibilityWP and WordPressCS sniffs are WP-specific; disable if unused. |
| Performance Overhead | Low | Parallel Lint mitigates this; exclude vendor/ and node_modules/ from scans. |
| Rule Conflicts | Medium | Audit existing PHPCS rules (e.g., PSR12) before adoption; use --diff to compare. |
| CI/CD Complexity | Low | Leverage composer check-cs-warnings and check-cs-thresholds for gatekeeping. |
SlevomatCodingStandard) or adopt it fully?YOASTCS_THRESHOLD_ERRORS)?squizlabs/php_codesniffer) or add YoastCS as a parallel standard?php -l sufficient?phpcs CLI (included in Laravel’s php binary).artisan test workflow (parallel execution for large codebases).composer.json hooks (e.g., post-autoload-dump).yoast/yoastcs in a phpcs step alongside Laravel’s pest/phpunit.yoastcs to Valet’s PHP extensions (if needed for local linting).yoast/yoastcs in Laravel Docker images for CI-local parity.| Phase | Action | Tools/Commands |
|---|---|---|
| Assessment | Audit existing codebase for PHPCS violations using YoastCS. | composer require --dev yoast/yoastcs + phpcs --standard=Yoast --report=full . |
| Baseline | Set initial thresholds (YOASTCS_THRESHOLD_ERRORS=0, WARNINGS=5). |
Update .env.ci or CI config. |
| Incremental Adoption | Fix critical errors first; use phpcs --diff to track progress. |
composer check-cs-warnings in CI. |
| Full Enforcement | Block merges on errors; relax warnings for legacy code. | Configure GitHub Actions/GitLab CI to fail on YOASTCS_ABOVE_THRESHOLD. |
| Optimization | Exclude non-PHP files (e.g., Blade templates) or adjust rulesets. | Custom .phpcs.xml or composer.json scripts. |
<exclude> to .phpcs.xml).NoFQNTrueFalseNull may conflict; override or document exceptions.PHPCompatibilityWP ensures backward compatibility with WordPress.^3.12.0; Laravel’s default may lag. Pin in composer.json:
"config": {
"allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true }
},
"require-dev": {
"yoast/yoastcs": "^3.0",
"phpcs/phpcs": "^3.12.0"
}
^8.15.0; ensure Laravel’s rector/pint don’t conflict.app() helper).composer check-cs-warnings to pull request checks before merging.check-cs-thresholds for release branches..phpcs.xml.dist template for new Laravel packages.composer.json to avoid breaking changes..phpcs.xml or custom sniffs for Laravel-specific patterns (e.g., Illuminate\Container usage).<config name="exclude_files" value=".*/vendor/.*|.*/resources/views/.*"/>
<rule ref="Yoast">
<exclude name="WordPress.WP.GetMetaSingle"/>
</rule>
How can I help you explore Laravel packages today?