LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

php-cs-fixer

Automatically fix PHP coding standards issues

TLDR

Fix current directory
$ php-cs-fixer fix
copy
Fix specific file
$ php-cs-fixer fix [file.php]
copy
Dry run showing what would change
$ php-cs-fixer fix --dry-run
copy
Show diff of changes
$ php-cs-fixer fix --diff
copy
Use specific rule set
$ php-cs-fixer fix --rules=@PSR12
copy
Fix with verbose output
$ php-cs-fixer fix -v
copy
List files that need fixing
$ php-cs-fixer list-files
copy

SYNOPSIS

php-cs-fixer command [options] [path]

DESCRIPTION

PHP CS Fixer automatically fixes PHP code to follow coding standards. It supports PSR-1, PSR-2, PSR-12, Symfony, and custom rule sets. The tool parses PHP files, applies configured fixers, and rewrites files with corrected formatting.

PARAMETERS

fix [PATH]

Fix coding standards in the given path or current directory.
check [PATH]
Shorthand for `fix --dry-run`. Analyze without modifying files.
--dry-run
Don't modify files, only show what would change.
--diff
Show a diff of applied changes.
--rules RULES
Coding standard rules or rule sets (e.g., @PSR12, @Symfony).
--config FILE
Path to configuration file.
--allow-risky yes|no
Allow risky rules that may change code behavior.
--using-cache yes|no
Enable or disable caching (default: yes).
--cache-file FILE
Path to cache file (default: .php-cs-fixer.cache).
--format FORMAT
Output format (txt, json, checkstyle, gitlab, junit, xml).
--stop-on-violation
Stop execution on first violation.
--path-mode override|intersection
How to treat paths from config vs command arguments (default: override).

CONFIGURATION

.php-cs-fixer.php or .php-cs-fixer.dist.php

PHP configuration file defining rules, finders, and project-specific settings. Searched in the current directory by default.

CAVEATS

Risky fixers may change code behavior and must be explicitly allowed. Configuration via PHP file provides more flexibility than command-line rules.

SEE ALSO

phpcs(1), phpcbf(1), php(1)

Copied to clipboard
Kai