dbrekelmans/coding-standard
PHP coding standard package based heavily on the Doctrine coding standard. Provides shared rules and configuration to enforce consistent formatting and style across projects, helping teams catch issues early and keep codebases clean.
Installation Update the package via Composer in your Laravel project:
composer require --dev dbrekelmans/coding-standard
Ensure php-cs-fixer is installed globally or as a dev dependency (v3.x+ recommended for compatibility):
composer require --dev friendsofphp/php-cs-fixer:^3.0
Configuration
Create or update .php-cs-fixer.dist.php to leverage the updated ruleset:
<?php
return (new PhpCsFixer\Config())
->setRules([
'@dbrekelmans/coding-standard' => true, // Updated to v1.3
'array_syntax' => ['syntax' => 'short'],
]);
First Use Case Run the updated coding standard fixer on a single file:
vendor/bin/php-cs-fixer fix app/Models/User.php
Or fix all files in a directory:
vendor/bin/php-cs-fixer fix app/
CI/CD Integration Update CI scripts to reflect the new ruleset:
{
"scripts": {
"test:cs": "php-cs-fixer fix --dry-run --diff --rules=@dbrekelmans/coding-standard"
}
}
Team Onboarding
.php-cs-fixer.dist.php (now using Doctrine v8.1) in team docs.git clone <repo>
composer install
composer cs-fix # Updated ruleset
Pre-Commit Hooks
Use the updated package with modern tools like php-cs-fixer v3.x:
composer require --dev friendsofphp/php-cs-fixer:^3.0
vendor/bin/php-cs-fixer fix --dry-run --diff
Integrate with tools like Husky or Laravel Pint.
Project-Specific Overrides Extend the updated ruleset (now based on Doctrine v8.1):
return (new PhpCsFixer\Config())
->setRules([
'@dbrekelmans/coding-standard' => true,
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
]);
Laravel-Specific Files Target Laravel files with the updated ruleset:
vendor/bin/php-cs-fixer fix database/migrations/ --rules=@dbrekelmans/coding-standard,ordered_class_elements
pint --config=.php-cs-fixer.dist.php
{
"php-cs-fixer.executablePath": "vendor/bin/php-cs-fixer",
"php-cs-fixer.rules": "@dbrekelmans/coding-standard"
}
Rule Conflicts
--dry-run:
vendor/bin/php-cs-fixer fix app/Http/Controllers/ --dry-run
array_syntax: Short syntax may now be enforced more strictly.concat_space: Doctrine v8.1 may enforce spaces in concatenation ($a . $b).Performance
--parallel for multi-core systems (supported in php-cs-fixer v3.x):
vendor/bin/php-cs-fixer fix --parallel
--cache-file=.php-cs-fixer.cache.False Positives
Route::group). Exclude or override:
->setRules([
'@dbrekelmans/coding-standard' => true,
'no_unused_imports' => false, // Disable if Facades cause issues
]);
Breaking Changes
php_unit_test_class_requires_covers) may now apply to tests.composer.json is compatible (e.g., no composer.lock conflicts).--dry-run to preview changes:
vendor/bin/php-cs-fixer fix --dry-run --diff
-v (now supported in php-cs-fixer v3.x):
vendor/bin/php-cs-fixer fix -v
vendor/bin/php-cs-fixer fix --rules=whitespace_after_comma
Custom Rules Add Laravel-specific rules to the updated config:
->setRules([
'@dbrekelmans/coding-standard' => true,
'return_type_declaration' => [
'space' => 'none',
'nullable_type_declaration_for_builtin_types' => false,
],
]);
Path Exclusions
Exclude vendor or generated files (now compatible with php-cs-fixer v3.x):
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('bootstrap/cache')
);
Git Integration
Use git diff with the updated ruleset:
git diff --name-only | xargs vendor/bin/php-cs-fixer fix --dry-run
Combining with Other Tools
pest or phpunit for test-specific rules:
vendor/bin/php-cs-fixer fix tests/ --rules=@dbrekelmans/coding-standard,no_unused_imports
psalm for static analysis alongside CS fixes.How can I help you explore Laravel packages today?