PHP-CS-Fixer vs PHP_CodeSniffer
debt(d3/e3/b3/t5)
Closest to 'default linter catches the common case' (d3). The detection_hints list php-cs-fixer and phpcs as tools with automated=yes — these are standard, widely adopted PHP style tools that catch style violations automatically in CI/pre-commit hooks. Style inconsistencies are visible immediately when these tools are run, though they require the tools to be set up first.
Closest to 'simple parameterised fix' (e3). The quick_fix describes adding a .php-cs-fixer.php config, running with --dry-run in CI, and hooking into pre-commit. This is a small setup task across a config file and CI definition — not a single-line patch but not a multi-file refactor either. Common mistake of fixing the whole codebase at once can be mitigated with --path-mode=intersection, keeping the remediation scope manageable.
Closest to 'localised tax' (b3). The choice applies across web, cli, and queue-worker contexts, meaning the whole PHP codebase pays the style-enforcement overhead. However, once the config is committed and the toolchain is set up, the ongoing maintenance burden is minimal — it's a tax on initial setup and occasional config updates, not on every future change.
Closest to 'notable trap — a documented gotcha most devs eventually learn' (t5). The misconception field highlights that teams think style enforcement is optional, but the deeper trap surfaced in common_mistakes is running --fix in CI instead of --dry-run — the 'obvious' CI setup (auto-fix everything) is actually wrong and should be reserved for local pre-commit hooks. This is a well-documented gotcha that most teams hit when first setting up the toolchain.
Also Known As
TL;DR
Explanation
PHP_CodeSniffer (phpcs/phpcbf): detects violations with phpcs, fixes them with phpcbf. Supports PSR-1/2/12, custom sniffs, ignoring specific rules. PHP-CS-Fixer: declarative configuration, auto-fixes everything — designed for full automation. Typically: PHP-CS-Fixer for auto-formatting (run in CI --dry-run, run locally to fix), PHPStan/Psalm for static analysis, PHP_CodeSniffer for project-specific custom sniffs. Configure once in .php-cs-fixer.dist.php committed to the repo.
Common Misconception
Why It Matters
Common Mistakes
- Running PHP-CS-Fixer with --fix in CI — CI should check (--dry-run), not auto-fix; fixes go in a local pre-commit hook.
- Not committing .php-cs-fixer.dist.php — team members use different configs, creating style inconsistencies.
- Running on the whole codebase at once when starting — fix incrementally with --path-mode=intersection to avoid massive diffs.
- Not using Prettier for JS alongside PHP-CS-Fixer for PHP — style tools should cover all file types in the project.
Code Examples
// No style enforcement — review noise:
// PR comments:
// 'Please add spaces around operators'
// 'Missing blank line before return'
// 'Use single quotes for strings'
// 'Closing brace should be on its own line'
// 10 style comments on every PR — reviewer time wasted
# .php-cs-fixer.dist.php:
<?php
$finder = PhpCsFixer\Finder::create()->in(__DIR__ . '/src');
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'@PHP82Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
])
->setFinder($finder);
# CI check:
php vendor/bin/php-cs-fixer fix --dry-run --diff
# Pre-commit hook: auto-fix locally
php vendor/bin/php-cs-fixer fix