m6web/coke
Coke is a CLI wrapper around PHP_CodeSniffer that lets you manage per-project rules via a .coke file. Run phpcs with easy include/exclude lists, optional “only git changed” mode, verbose output, and pass through any phpcs arguments.
Installation:
composer require --dev m6web/coke
(Note: Despite being deprecated, this package can still be used for legacy projects or specific use cases.)
Basic Usage:
.phpcs.xml or .phpcs.xml.dist configuration file:
vendor/bin/coke generate
First Use Case:
standard, ruleset, or exclude paths) to match your team’s coding standards.vendor/bin/phpcs -n --standard=./.phpcs.xml src/
.phpcs.xml for default rules (e.g., PSR1/PSR2, custom sniffs).--sniffs, --exclude flags).Onboarding New Projects:
composer.json under require-dev and run generate in post-install-cmd:
{
"scripts": {
"post-install-cmd": [
"@php ./vendor/bin/coke generate"
]
}
}
.phpcs.xml to version control for consistency.Team Standardization:
PSR12.Methods.MethodDeclaration).<config name="standard" value="PSR12" />
<rule ref="PSR12" />
<rule ref="Generic.Files.LineEndings" severity="warning" />
CI/CD Pipeline:
- name: Run PHPCS
run: vendor/bin/phpcs -n --standard=.phpcs.xml src/ tests/
--sniffs flag to include custom sniffs (e.g., ./Sniffs/ClassLengthSniff.php):
vendor/bin/coke generate --sniffs="PSR12,./Sniffs/*"
./config/phpcs-frontend.xml for frontend-specific rules).Deprecation Warning:
squizlabs/php_codesniffer directly or modern tools like dealerdirect/phpcodesniffer-composer-installer.Config Overrides:
.phpcs.xml files. Backup before running generate.Sniff Path Issues:
./Sniffs/. Coke doesn’t auto-detect Composer-autoloaded sniffs.vendor/bin/phpcs --config=.phpcs.xml --test
--verbose with Coke to debug generation:
vendor/bin/coke generate --verbose
Custom Templates:
--template flag to use a custom XML skeleton.Post-Generation Hooks:
composer scripts to run additional commands after Coke:
{
"scripts": {
"post-coke": [
"@php ./scripts/tweak-phpcs-config.php"
]
}
}
git update-index --assume-unchanged .phpcs.xml).--cache flag for faster repeated runs..phpcs.xml:
<ruleset>
<config name="standard" value="PSR12"/>
<file>./src/</file>
</ruleset>
RuleSet or Config classes in PHP for dynamic generation.How can I help you explore Laravel packages today?