LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

phpcbf

PHP Code Beautifier and Fixer

TLDR

Fix coding standard violations in a file
$ phpcbf [path/to/file.php]
copy
Fix all files in a directory
$ phpcbf [path/to/src/]
copy
Fix using a specific coding standard
$ phpcbf --standard=[PSR12] [path/to/file.php]
copy
Fix only specific sniffs
$ phpcbf --sniffs=[Sniff.Name] [path/to/file.php]
copy
Write fixed files with a suffix instead of overwriting
$ phpcbf --suffix=[.fixed] [path/to/file.php]
copy
Fix only specific file extensions
$ phpcbf --extensions=[php,inc] [path/to/src/]
copy

SYNOPSIS

phpcbf [options] [files...]

DESCRIPTION

phpcbf (PHP Code Beautifier and Fixer) automatically corrects coding standard violations detected by phpcs. It is the companion fixer tool in the PHP_CodeSniffer package.The tool modifies files in-place by default, applying fixes for violations that have an automatic fixer defined. Not all phpcs violations are auto-fixable; phpcbf will only fix those with corresponding fixer implementations. Use --suffix to write fixed copies instead of overwriting originals, or --diff to generate a patch without modifying files.

PARAMETERS

FILES

Files or directories to fix.
--standard=NAME
Coding standard to use (e.g., PSR1, PSR2, PSR12, Squiz, PEAR).
--sniffs=LIST
Comma-separated list of specific sniffs to apply.
--exclude=LIST
Comma-separated list of sniffs to exclude.
--extensions=LIST
Comma-separated file extensions to fix (default: php,inc). Can include type: module/php,es/js.
--suffix=SUFFIX
Write fixed files with this suffix instead of overwriting originals.
--no-patch
Use PHP for file replacement instead of diff/patch commands.
--diff
Generate a diff of changes instead of applying them.
-p
Show progress during fixing.
--help
Display help information.

CAVEATS

Part of PHP_CodeSniffer. Not all coding standard violations are automatically fixable. Always review changes after fixing, especially on first use with a codebase.

HISTORY

PHPCBF is part of PHP_CodeSniffer, originally by Greg Sherwood (Squiz Labs), now maintained by PHPCSStandards.

SEE ALSO

Copied to clipboard
Kai