PHP_CodeSniffer

Author(s)
Greg Sherwood
Website
https://pear.php.net/package/PHP_CodeSniffer
License
BSD 3-clause "New" or "Revised" License
Wiki
https://github.com/squizlabs/PHP_CodeSniffer/wiki
GitHub
squizlabs/PHP_CodeSniffer
Packagist
squizlabs/php_codesniffer
DockerHub
phpqa/phpcs

0 0 0

PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.

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.

Installation

Install from a Composer package as a dev dependency (with Composer)

Make sure you have Composer installed.

Require it as a dev dependency:
composer require --dev squizlabs/php_codesniffer
Run it:
php vendor/bin/phpcs

Install from a Composer package as a global CLI utility (with Composer)

Make sure you have Composer installed.

Require it as a global CLI utility:
composer global require squizlabs/php_codesniffer
Run it:
phpcs
Make sure your global vendor binaries directory is in your $PATH environment variable. Check the Composer documentation for more information.

Install from a Git repository (with Git)

Make sure you have git installed.

Git clone the repository:
git clone git://github.com/squizlabs/PHP_CodeSniffer.git
Change into the new directory:
cd PHP_CodeSniffer
Run it:
bin/phpcs

Install from a PEAR package (with PEAR)

Commandline
Install it:
pear install PHP_CodeSniffer

Install from a PHP Archive (with curl or wget)

The PHPUnit documentation has a clear manual on how to install PHARs on Windows.

If you have the Suhosin extension enabled, make sure to allow the execution of PHARs in your php.ini:
suhosin.executor.include.whitelist = phar

Locally
Download it:
wget -O phpcs.phar https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
or
curl -sSL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -o phpcs.phar
Use it:
php phpcs.phar
Globally
Download it:
wget -O phpcs.phar https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
or
curl -sSL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -o phpcs.phar
Install it as an executable:
chmod a+x phpcs.phar
sudo mv phpcs.phar /usr/local/bin/phpcs
Use it:
phpcs