woohoolabs/coding-standard
Woohoo Labs PHP Coding Standard for PHP_CodeSniffer, based on PSR-12 and inspired by Doctrine and Slevomat rules. Install via Composer and drop in the provided phpcs.xml to start enforcing consistent code style (PHP 7.4+).
Installation
composer require --dev woohoolabs/coding-standard
Update composer.json under require-dev to reflect the new dependency version:
"extra": {
"coding-standard": {
"ruleset": "woohoolabs"
}
}
First Run Integrate with PHP-CS-Fixer (now aligned with slevomat/coding-standard v8):
composer require --dev friendsofphp/php-cs-fixer
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --dry-run
First Use Case
Use as a pre-commit hook (via php-cs-fixer) or in CI (e.g., GitHub Actions):
# .github/workflows/php-cs.yml
- name: PHP Coding Standard
run: vendor/bin/php-cs-fixer fix --rules=@woohoolabs --allow-risky=yes
Local Development
--diff to preview changes:
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --diff
--dry-run to check without modifying files.CI/CD Integration
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --allow-risky=yes --stop-on-violation
Customization
.php-cs-fixer.dist.php (now compatible with slevomat/coding-standard v8):
return (new PhpCsFixer\Config())
->setRules([
'@woohoolabs' => true,
'no_unused_imports' => true, // Add custom rules
]);
Artisan Integration Create a custom command to enforce standards:
php artisan make:command FixCodingStandard
// app/Console/Commands/FixCodingStandard.php
public function handle() {
$this->call('php-cs-fixer', ['--rules=@woohoolabs']);
}
Register in app/Console/Kernel.php:
protected $commands = [
\App\Console\Commands\FixCodingStandard::class,
];
IDE Support Configure your IDE (PHPStorm/VSCode) to use the updated ruleset:
// .vscode/settings.json
"php-cs-fixer.executablePath": "vendor/bin/php-cs-fixer",
"php-cs-fixer.rules": "@woohoolabs"
Rule Conflicts
.php-cs-fixer.dist.php:
'array_syntax' => ['syntax' => 'short'],
'no_unused_private_properties' => ['ignore_unused_defined_properties' => true],
Performance
php-cs-fixer. Use --parallel:
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --parallel
Deprecated Rules
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --dry-run --verbose
Verbose Output
Use --verbose to diagnose rule application:
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --verbose
Rule Isolation Test individual rules:
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --only=@woohoolabs\type_declaration
Custom Rules
Extend the ruleset by creating a new rule file (e.g., ruleset/laravel.php):
return [
'@woohoolabs' => true,
'no_unused_imports' => true,
'native_function_invocation' => ['include' => ['@'], 'scope' => 'all'],
];
Reference it in composer.json:
"extra": {
"coding-standard": {
"ruleset": "ruleset/laravel"
}
}
Git Hooks
Automate enforcement via pre-commit:
composer require --dev laravel/git-hooks
vendor/bin/git-hooks install
Configure in .git/hooks/pre-commit:
#!/bin/sh
vendor/bin/php-cs-fixer fix --rules=@woohoolabs --allow-risky=yes --stop-on-violation
Documentation
vendor/bin/php-cs-fixer fix --dry-run --rules=@woohoolabs --format=diff to review changes.How can I help you explore Laravel packages today?