Developer Tools

PHP_CodeSniffer: Coding Standard Checks

PHP_CodeSniffer checks PHP source files against coding standards and can automatically fix many reported violations.

Overview

PHP_CodeSniffer is a development tool that tokenizes PHP files and reports violations of a selected coding standard. It is commonly used to keep code consistent across projects and teams.

Main commands

The phpcs command reports standard violations. The phpcbf command can automatically correct many fixable issues. The project can select a standard such as PSR-12 or maintain its own ruleset.

Team workflow

Keep the ruleset in version control and run checks before merging changes. Start by checking a limited directory, review the report and decide which rules fit the project's existing conventions. Automatic fixes should be reviewed like any other code change.

Official resource

PHP_CodeSniffer project and documentation: https://github.com/PHPCSStandards/PHP_CodeSniffer

Additional notes consolidated from the previous entry

Overview

PHP_CodeSniffer detects coding standard violations and can automatically fix many formatting issues.

Example

composer require --dev squizlabs/php_codesniffer
vendor/bin/phpcs --standard=PSR12 src
vendor/bin/phpcbf --standard=PSR12 src

Configure a project standard and run checks before merging changes.

Official repository: PHP_CodeSniffer

Evaluation checklist

  • Prefer official documentation and repositories.
  • Check supported PHP versions and release history.
  • Review installation instructions and license terms.
  • Keep dependencies updated and run security checks.
Share this page Help other developers discover this resource.