编程语言
首页 > 编程语言> > php必不可少的开发工具CodeSniffer代码规范phpcs检测及phpcb

php必不可少的开发工具CodeSniffer代码规范phpcs检测及phpcb

作者:互联网

PHP_CodeSniffer 是一个代码风格检测工具。由两个PHP脚本的组成;

要求

PHP_CodeSniffer需要PHP 5.4.0或更高版本,尽管单个嗅探可能还有其他要求,例如外部应用程序和脚本。有关这些要求的列表,请参见“配置选项”手册页。

如果您将PHP_CodeSniffer作为团队的一部分使用,或者正在CI服务器上运行它,则可能需要使用配置文件来配置项目的设置。

安装

# 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

如果使用Composer,则可以使用以下命令在系统范围内安装PHP_CodeSniffer:
composer global require "squizlabs/php_codesniffer=*"

确保PATH中包含作曲家bin目录。默认值为~/.composer/vendor/bin/,但是您可以通过运行来检查需要使用的值composer global config bin-dir --absolute。

或者,squizlabs/php_codesniffer在composer.json文件中包含的依赖项。例如:

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

然后,您将能够从供应商的bin目录中运行PHP_CodeSniffer:

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

Git

您还可以下载PHP_CodeSniffer源代码,phpcs并phpcbf直接从Git克隆中运行和命令:

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

标签:bin,phpcb,phpcbf,phpcs,squizlabs,CodeSniffer,PHP
来源: https://blog.csdn.net/hdl17822307857/article/details/112691623