PHP-CS-Fixer vs PHP_CodeSniffer
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
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
28
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 7
Perplexity 7
Google 4
SEMrush 3
Unknown AI 2
Ahrefs 2
Also referenced
How they use it
crawler 22
crawler_json 3
Related categories
⚡
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
🔍 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