php essential development tool CodeSniffer code specification phpcs detection and phpcb

PHP_CodeSniffer is a code style detection tool. Composed of two PHP scripts;

  • GitHub address

  • The phpcs script defines a series of code specifications for PHP, JavaScript, and CSS files (usually using official code specifications, such as PHP’s PSR2), which can detect codes that do not conform to the code specifications and issue warnings or errors (error level can be set ).

  • The phpcbf script can automatically correct the non-compliant parts of the code format. For example, in the PSR2 specification, a blank line is required at the end of every PHP file, so after running this script, a blank line will be automatically added at the end.

  • PHP_CodeSniffer is an essential development tool to ensure that your code remains clean and consistent.

Claim

PHP_CodeSniffer requires PHP 5.4.0 or higher, although a single sniff may have other requirements, such as external applications and scripts. For a list of these requirements, see the "Configuration Options" man page.

If you use PHP_CodeSniffer as part of a team, or are running it on a CI server, you may need to use a configuration file to configure the settings of your project.

installation

# Download using curlcurl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar# Or download using wgetwget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
wget https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar# Then test the downloaded PHARsphp phpcs.phar -h
php phpcbf.phar -h1234567891011

Composer

If you use Composer, you can install PHP_CodeSniffer system-wide using the following command:
composer global require "squizlabs/php_codesniffer=*"

Make sure that the composer bin directory is included in the PATH. The default value is ~/.composer/vendor/bin/, but you can check the value you need to use by runningcomposer global config bin-dir --absolute。

Or, squizlabs/php_codesniffer includes the dependencies in the composer.json file. E.g:

{
     “ require-dev ”:{
         “ squizlabs / php_codesniffer ”:“ 3. * ” 
    } }12345

Then, you will be able to run PHP_CodeSniffer from the vendor's bin directory:

./vendor/bin/phpcs -h./vendor/bin/phpcbf -h12

Git

You can also download the PHP_CodeSniffer source code, phpcs and phpcbf to run and commands directly from the Git clone:

git clone https://github.com/squizlabs/PHP_CodeSniffer.git
cd PHP_CodeSniffer
php bin/phpcs -h
php bin/phpcbf -h

Guess you like

Origin blog.csdn.net/yy17822307852/article/details/112862802
Recommended