yoast/yoastcs
Yoast Coding Standards (YoastCS) provides Composer-installable rulesets and tooling for PHP code style and quality in Yoast projects, including PHP_CodeSniffer standards/sniffs and PHP Parallel Lint. Integrates via Composer for consistent CI enforcement.
Strengths:
SlevomatCodingStandard for modern PHP practices) while ignoring WordPress-specific rules.Threshold report enables CI/CD integration for enforcing coding standards, aligning with Laravel’s emphasis on automated quality gates.Gaps:
snake_case migrations). Would require custom sniffs or exclusion of conflicting WordPress rules.composer require --dev yoast/yoastcs. The phpcs binary is auto-installed, reducing setup friction.composer check-cs-warnings and check-cs-thresholds scripts. Can be gated as a pre-merge requirement."minimum-stability": "dev" in composer.json, which may break builds if not explicitly configured. Risk: Medium (mitigated by pinning versions).checkIfConditions) may fail on older versions. Risk: Low if using LTS releases.--exclude).VariableAnalysis) could cause timeouts. Risk: Medium (mitigate with --parallel flag).WordPress.WP.GetMetaSingle) may flag Laravel code as violations. Risk: High (requires custom .phpcs.xml exclusions).YOASTCS_THRESHOLD_ERRORS/WARNINGS be set?phpstan, psalm, or pint) or run in parallel?husky) to run PHPCS locally?PHPCompatibilityWP alpha dependencies)?RequireNullCoalesceOperator.WordPress.WP.GetMetaSingle) are irrelevant and should be disabled via .phpcs.xml:
<rule ref="WordPress.WP.GetMetaSingle">0</rule>
pint (for formatting) and phpstan (for static analysis). Can be chained in CI:
# Example GitHub Actions step
- name: Run PHPCS
run: composer check-cs-warnings
- name: Run PHPStan
run: composer test:phpstan
vendor/bin/phpcs --standard=Yoast --report=full src/ tests/
snake_case but Yoast enforces camelCase for variables")..phpcs.xml to:
SlevomatCodingStandard warnings to info).<config name="installed_paths" value="./vendor/yoast/yoastcs"/>
<rule ref="SlevomatCodingStandard.Arrays.ArrayAccess">1</rule>
<rule ref="WordPress">0</rule> <!-- Disable all WordPress sniffs -->
composer.json:
"scripts": {
"check-cs": "phpcs --standard=Yoast --report=threshold src/ tests/",
"check-cs-thresholds": "phpcs --standard=Yoast --report=YoastCS\\Yoast\\Reports\\Threshold src/ tests/"
}
YOASTCS_ABOVE_THRESHOLD=true.composer require --dev laravel/pint
composer require --dev dealerdirect/phpcodesniffer-composer-installer
@phpcs:disable for legacy code").resources/views/:
phpcs --standard=Yoast --ignore=resources/views/
@codeCoverageIgnore or exclude app/Console/ if sniffs conflict.2.1.6) in composer.json:
"extra": {
"yoastcs-phpcompatibilitywp": "2.1.6"
}
phpcs is updated (^3.12.0) to avoid runtime errors.SlevomatCodingStandard and PHPCSExtra (framework-agnostic).error-level issues (blocked in CI).warning-level issues (threshold-based).pint (formatting) but before phpstan (static analysis) in CI.PHPCompatibilityWP alpha dependencies).composer why-not yoast/yoastcs to test updates before merging.phpcs --generate=xml to diff rule sets across versions.How can I help you explore Laravel packages today?