Installation
composer require --dev coffreo/php-cs-fixer-config
Add the config to your project’s composer.json under "extra":
"extra": {
"coffreo-cs-fixer": {
"rules": "@coffreo"
}
}
First Use Case Run PHP-CS-Fixer with Coffreo’s preset:
vendor/bin/php-cs-fixer fix --rules=@coffreo
Or integrate it into your php-cs-fixer.dist.php:
return (new PhpCsFixer\Config())
->setRules([
'@coffreo' => true,
]);
Where to Look First
vendor/bin/php-cs-fixer fix --dry-run --diff --rules=@coffreo
Team-Wide Enforcement
Commit the preset to version control (e.g., php-cs-fixer.dist.php) to ensure consistency across the team.
Example:
return (new PhpCsFixer\Config())
->setRules([
'@coffreo' => true,
'risky' => false, // Disable risky rules if needed
]);
CI/CD Integration Add a GitHub Actions step (or equivalent) to auto-fix on push:
- name: Fix CS
run: vendor/bin/php-cs-fixer fix --rules=@coffreo --allow-risky=yes
Customizing the Preset Override specific rules while keeping Coffreo’s base:
return (new PhpCsFixer\Config())
->setRules([
'@coffreo' => true,
'phpdoc_align' => false, // Disable a Coffreo rule
'array_syntax' => ['syntax' => 'short'], // Customize a rule
]);
Pre-Commit Hooks
Use php-cs-fixer with tools like Husky or Pre-commit:
composer require --dev php-cs-fixer
echo "vendor/bin/php-cs-fixer fix --rules=@coffreo --dry-run" >> .git/hooks/pre-commit
php-cs-fixer fix once during setup to align existing code.--dry-run to preview changes before committing:
vendor/bin/php-cs-fixer fix --dry-run --diff --rules=@coffreo
laravel-pint (if using) by running both tools in CI.{
"php": {
"codeSnifferConfig": "vendor/bin/php-cs-fixer",
"codeSnifferRules": "@coffreo"
}
}
Outdated Preset The package hasn’t been updated since 2020. Verify rules align with modern PHP-CS-Fixer (v3.x+).
Risky Rules
Coffreo’s preset may include @Risky rules (e.g., no_unused_imports). Disable them if strictness is undesired:
->setRules([
'@coffreo' => true,
'risky' => false,
]);
Path Configuration If running in a monorepo or custom directory structure, specify paths explicitly:
vendor/bin/php-cs-fixer fix --rules=@coffreo --path-mode=intersection --path="src/"
Caching Issues Clear PHP-CS-Fixer’s cache if rules seem ignored:
vendor/bin/php-cs-fixer cache-clear
--verbose to debug rule application:
vendor/bin/php-cs-fixer fix --verbose --rules=@coffreo
--dry-run before committing fixes:
vendor/bin/php-cs-fixer fix --dry-run --diff
extra.coffreo-cs-fixer key. If missing, define it explicitly in php-cs-fixer.dist.php:
->setRules([
'@coffreo' => true,
// Fallback if key is missing
'array_syntax' => ['syntax' => 'short'],
]);
Custom Preset
Extend Coffreo’s rules by creating a new preset file (e.g., cs-fixer.php):
return (new PhpCsFixer\Config())
->setRules([
'@coffreo' => true,
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
]);
Dynamic Rule Loading Load rules dynamically from a config file:
$rules = require __DIR__ . '/cs-fixer-rules.php';
return (new PhpCsFixer\Config())->setRules($rules);
Parallel Processing Speed up large codebases with parallel fixes:
vendor/bin/php-cs-fixer fix --parallel --rules=@coffreo
How can I help you explore Laravel packages today?