← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

PHP-CS-Fixer vs PHP_CodeSniffer

Style PHP 7.1+ Beginner
debt(d3/e3/b3/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

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.

e3 Effort Remediation debt — work required to fix once spotted

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.

b3 Burden Structural debt — long-term weight of choosing wrong

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.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

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.

About DEBT scoring →

Also Known As

PHP-CS-Fixer PHP_CodeSniffer phpcs phpcbf code style

TL;DR

Two PHP code style tools: PHP_CodeSniffer detects and optionally fixes violations, PHP-CS-Fixer auto-fixes code to match a configured style — both enforce consistent formatting across a codebase.

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

Code style enforcement is optional for small teams — inconsistent style increases cognitive load during code review and causes noisy diffs; automation eliminates the debate entirely.

Why It Matters

Automated style enforcement removes all style debates from code review — reviewers focus on logic and architecture, not indentation and bracket placement.

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

✗ Vulnerable
// 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
✓ Fixed
# .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

Added 15 Mar 2026
Edited 22 Mar 2026
Views 73
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 3 pings S 1 ping S 0 pings M 1 ping T 0 pings W 5 pings T 5 pings F 2 pings S 5 pings S 2 pings M 1 ping T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 17 Amazonbot 9 Google 8 Perplexity 7 ChatGPT 6 SEMrush 5 Ahrefs 4 Unknown AI 2 Claude 1 Meta AI 1 DuckDuckGo 1 Sogou 1 PetalBot 1
crawler 58 crawler_json 5
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Add a .php-cs-fixer.php config targeting PSR-12, run in CI with --dry-run --diff to catch violations, and in pre-commit hooks to auto-fix before committing
📦 Applies To
PHP 7.1+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Inconsistent PHP code style; mixed tabs/spaces; no .php-cs-fixer.php config in project
Auto-detectable: ✓ Yes php-cs-fixer phpcs rector
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Low ✓ Auto-fixable Fix: Low Context: File


✓ schema.org compliant