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.
Installation:
composer require --dev yoast/yoastcs:"^3.0"
Ensure allow-plugins is configured in composer.json:
{
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
First Run:
Parallel Lint (syntax checks):
composer lint
(Add this script to composer.json scripts section as shown in README.)
PHPCS (coding standards):
vendor/bin/phpcs --standard=Yoast src/
Key Files:
.phpcs.xml.dist (default config, auto-generated by YoastCS)composer.json (scripts for linting/threshold checks)Daily Development:
# Add to .git/hooks/pre-commit
#!/bin/sh
vendor/bin/phpcs --standard=Yoast --report=full src/ || exit 1
- name: Run PHPCS
run: vendor/bin/phpcs --standard=Yoast --report=full src/ || exit 1
Threshold Enforcement:
YOASTCS_THRESHOLD_ERRORS=5 YOASTCS_THRESHOLD_WARNINGS=20 vendor/bin/phpcs --standard=Yoast --report=YoastCS\Yoast\Reports\Threshold src/
composer check-cs-thresholds
Custom Configurations:
.phpcs.xml.dist:
<config name="minimum_wp_version" value="6.8" /> <!-- Override default -->
<rule ref="Yoast">
<exclude name="Yoast.Arrays.ArrayAccess" /> <!-- Disable specific sniff -->
</rule>
Parallel Lint in CI:
composer lint -- --cache=/tmp/parallel-lint-cache
Laravel-Specific:
vendor/ and bootstrap/cache/ in PHPCS:
<arg name="exclude" value="vendor,bootstrap/cache" />
app/, config/, and routes/:
vendor/bin/phpcs --standard=Yoast app/ config/ routes/
PhpStorm Setup:
Settings > Languages & Frameworks > PHP > Code Sniffer.Yoast.Custom Sniffs:
.phpcs.xml.dist:
<rule ref="Yoast.Arrays.DisallowShortArraySyntax" />
PHP Version Mismatches:
<config name="minimum_php_version" value="7.2" />
<config name="minimum_wp_version" value="6.6" />
Threshold Report Quirks:
YOASTCS_THRESHOLD_EXACT_MATCH to detect if thresholds need updates:
if (defined('YOASTCS_THRESHOLD_EXACT_MATCH') && !YOASTCS_THRESHOLD_EXACT_MATCH) {
echo "Thresholds need adjustment!";
}
SlevomatCodingStandard Issues:
<exclude name="SlevomatCodingStandard.Arrays.ArrayAccess" />
Parallel Lint False Positives:
node_modules/ or other non-PHP files:
composer lint -- --exclude=node_modules
Verbose Output:
vendor/bin/phpcs -e --standard=Yoast
vendor/bin/phpcs --standard=Yoast --generator=Text
Fixers:
vendor/bin/phpcbf --standard=Yoast --report=full src/
CI Failures:
YOASTCS_ABOVE_THRESHOLD in CI logs to debug threshold breaches.Custom Rulesets:
.phpcs.xml.dist:
<ruleset>
<rule ref="Yoast">
<exclude name="Yoast.Arrays.DisallowShortArraySyntax" />
</rule>
<config name="minimum_wp_version" value="6.5" />
</ruleset>
Plugin Integration:
phpcs --config-file=.phpcs.xml.dist to load project-specific configs.Parallel Lint Optimization:
composer lint -- --workers=4
How can I help you explore Laravel packages today?