How squizlabs/php_codesniffer works
PHP_CodeSniffer analyzes PHP, JavaScript, and CSS files against configurable coding standards, reports violations, and can automatically fix fixable violations. The principal workflow is selecting files and rules, tokenizing source, running registered sniffs, then reporting findings or applying fixes. The tree and excerpts support the major stages and capabilities, but do not expose the full Runner, Reporter, or Fixer implementations; some internal wiring is therefore omitted. The standards directory represents the included rule sets rather than a single sniff.
Main entry points: Runner.php Runner · File.php Analysis file · Ruleset.php Ruleset · FileList.php File discovery
Components 17
Run orchestration
- Runner
src/Runner.php - Run config
src/Config.php - Ruleset
src/Ruleset.php - File discovery
src/Files/FileList.php - File filters
src/Filters/Filter.php
Token analysis
- Analysis file
src/Files/File.php - PHP tokenizer
src/Tokenizers/PHP.php - JavaScript tokenizer
src/Tokenizers/JS.php - CSS tokenizer
src/Tokenizers/CSS.php - Token utilities
src/Util/Tokens.php - Sniff API
src/Sniffs/Sniff.php - Included standards
src/Standards
Automatic correction
- Fixer
src/Fixer.php
Reports and docs
- Reporter
src/Reporter.php - Report formats
src/Reports/Report.php - Standard docs
src/Generators/Generator.php
Other components
- Developer
Connections 17
- Developer → Runner: invokes checks
- Developer → Fixer: invokes fixes
- Runner → Run config: reads options
- Runner → Ruleset: loads rules
- Runner → File discovery: selects files
- File discovery → File filters: filters paths
- Runner → Analysis file: checks files
- Analysis file → PHP tokenizer: tokenizes PHP
- Analysis file → JavaScript tokenizer: tokenizes JavaScript
- Analysis file → CSS tokenizer: tokenizes CSS
- PHP tokenizer → Token utilities: uses token groups
- Ruleset → Included standards: loads sniffs
- Included standards → Sniff API: implements rules
- Runner → Reporter: collects results
- Reporter → Report formats: renders findings
- Analysis file → Fixer: applies changes
- Developer → Standard docs: generates docs