PHP CodeSniffer

PHPCS is a tool that helps detect violations of pre-defined coding standards. It also includes an additional tool that can automatically correct those violations

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Requirements
PHP_CodeSniffer requires PHP version 5.4.0 or greater, although individual sniffs may have additional requirements such as external applications and scripts.

If you’re using PHP_CodeSniffer as part of a team, or you’re running it on a Continuous Integration(CI) server, you may want to configure your project’s settings using a configuration file.

Installation

Please refer the URL = https://github.com/squizlabs/PHP_CodeSniffer

 

PHPCS commands

// Discover violation of coding standards
phpcs –standard=Drupal –extensions=php,module,inc,install,test,profile,theme,css,info,txt,md /path/to/drupal/example_module

phpcs –standard=Drupal /to/drupal/example_module

// Automatically fix coding standards
phpcbf –standard=Drupal /to/drupal/example_module

phpcs –standard=DrupalPractice –extensions=php,module,inc,install,test,profile,theme,css,info,txt,md /path/to/drupal/example_module