PHP CS Fixer

CLI tool that automatically fixes PHP code to follow coding standards

Tool
Composer
vv3.95.27
13,567 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
93 /100 Excellent
Development Activity 92
Maintenance 96
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
85 /100 Excellent
Architecture 88
Code Quality 92
Innovation 78
Learning Curve 80

PHP CS Fixer is a command-line tool that doesn’t just detect PHP coding-standards violations like a linter — it rewrites the code to fix them. It ships built-in rule sets for widely used standards (PHP-FIG’s PER Coding Style, the Symfony coding standard, and its own opinionated @PhpCsFixer set), plus migration rule sets that help modernize a codebase toward newer PHP and PHPUnit syntax.

Teams typically run it via Composer (composer require --dev friendsofphp/php-cs-fixer) and invoke it as php-cs-fixer fix to auto-format a codebase, or php-cs-fixer check in CI to fail a build on style drift, with a project-level configuration file for defining custom rule combinations beyond the built-in sets.

What You Get

  • A php-cs-fixer CLI with fix (rewrite files) and check (report-only, CI-friendly) commands
  • Built-in rule sets for PER Coding Style, Symfony’s coding standard, and the tool’s own opinionated @PhpCsFixer set
  • Auto-migration rule sets (@autoPHPMigration, @autoPHPUnitMigration:risky) that modernize syntax toward newer PHP/PHPUnit versions
  • A configuration-file system (.php-cs-fixer.php/dist.php) for composing custom rule combinations and per-project overrides
  • A custom_rules extension point for teams that need style rules the built-in fixer set doesn’t cover

Common Use Cases

  • Enforcing a consistent code style across a team automatically, instead of relying on manual review comments for formatting nits
  • Gating pull requests in CI with php-cs-fixer check --dry-run, failing the build if any file doesn’t match the configured rule set
  • Migrating a legacy codebase’s syntax toward a newer PHP version’s idioms in bulk via the auto-migration rule sets
  • Adopting a well-known standard (PER-CS, Symfony) on a new project in one command instead of hand-writing a style guide

Under The Hood

Architecture The tool centers on src/Tokenizer (a custom PHP token stream abstraction), src/Fixer (hundreds of individual fixer classes, each implementing one style rule against that token stream), src/RuleSet (named collections of fixers, e.g. @Symfony/@PER-CS), src/Runner and src/Differ (applying fixers across a fileset and computing diffs), src/Cache (incremental-run caching keyed by file hash and ruleset), and src/Console (the CLI command layer wrapping all of the above into fix/check); src/Linter cross-checks fixer output against PHP’s own syntax validity.

Tech Stack It’s a PHP 7.4–8.5 Composer package with symfony/console powering its CLI, its own token-stream/AST-adjacent tooling for source manipulation rather than relying on an external PHP parser, and a Docker-based (Dockerfile/compose.yaml) workflow supporting containerized usage in CI; box.json.dist indicates it’s also distributed as a self-contained PHAR via php-cs-fixer/shim for dependency-conflict-free installs.

Code Quality The repository has an exceptionally large test suite (1,200+ test files) covering essentially every individual fixer plus integration tests, PHPStan static analysis (phpstan.dist.neon) and Infection mutation testing (infection.json5.dist) configured for the CI pipeline, and a composer-dependency-analyser.php check — reflecting the discipline expected of a tool that itself enforces coding standards for thousands of downstream projects. Repo health score of 95/100 reflects very active, well-maintained, rapidly growing development.

API Design The CLI surface is deliberately small (init, fix, check) with rule-set selection doing most of the configuration work, so adopting a standard is typically a one-line config change, while the fixer/rule-set architecture is fully extensible for teams that need custom rules beyond the built-ins.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers