PHP_CodeSniffer

Tokenizes PHP files and detects (and auto-fixes) violations of defined coding standards.

Tool
Composer
v4.0.4
1,546stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
88/100Excellent
Development Activity96
Maintenance100
Community68
Maturity48
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture86
Code Quality88
Innovation78
Learning Curve74

PHP_CodeSniffer is the standard toolkit for enforcing coding conventions across PHP codebases. Its phpcs command tokenizes source files and reports where they deviate from a chosen ruleset, while its companion phpcbf automatically fixes many of those violations in place, keeping teams aligned on style without manual review.

It ships with built-in standards such as PSR-1 and PSR-12 and supports fully custom rulesets, so organizations can codify their own conventions and run them locally, in editors, and in CI. This actively maintained PHPCSStandards release is the community successor to the original squizlabs project.

What You Get

  • The phpcs command-line linter for detecting standard violations
  • The phpcbf command for automatically fixing many violations
  • Built-in standards including PSR-1 and PSR-12
  • Custom ruleset support via XML configuration
  • An extensible sniff and tokenizer architecture for authoring rules

Common Use Cases

  • Enforcing a consistent coding standard across a PHP team
  • Automatically fixing style violations before commit
  • Gating pull requests on coding-standard compliance in CI
  • Authoring and distributing a custom organizational ruleset

Under The Hood

Architecture - The tool centers on a tokenizer that converts PHP (and CSS/JS) source into a stream of tokens, which individual Sniff classes inspect to flag or fix violations. Rulesets (XML) compose sniffs from one or more standards; the Runner orchestrates file discovery, tokenizing, sniff execution, and reporting, while phpcbf re-runs sniffs in fixing mode to apply corrections. Reports are pluggable (full, summary, checkstyle, JSON, etc.).

Tech Stack - Pure PHP with a very small runtime footprint (core ext-tokenizer, ext-xmlwriter, ext-simplexml), distributed both as a Composer package and as standalone PHARs. Its architecture is deliberately dependency-light so it can run anywhere PHP does.

Code Quality - The project is mature and rigorously self-tested, with an extensive suite covering the tokenizer and each bundled sniff. Under the PHPCSStandards maintainers it has seen renewed, consistent activity and disciplined releases, reflected in its strong maintenance-consistency health score.

API Design - As a CLI tool the developer experience is excellent: sensible defaults, discoverable options, and a clear XML ruleset format make adoption fast. Writing custom sniffs requires understanding the token stream, which is the main learning curve, but the bundled standards and thorough documentation ease the path.

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

Search