PHP Coding Standards Fixer, PHP_CodeSniffer, php_Coding Standards Fixer, PHP_CodeSniffer, php_Coding Standards Fixer, php_Coding Standards Fixer, php_Coding Standards Fixer, php_Coding Standards Fixer
Use bash to implement Git commit. Check for syntax errors in PHP files. Other languages can also be used for reference, it is very imaginative, can achieve a lot of things.
PHP Coding Standards Fixer
The PHP version must be 5.6.0 or greater
There are plug-ins for Atom, NetBeans, PhpStorm, Sublime Text, Vim, and other editors
PHP Coding Standards Fixer 官网
The installation
wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer
chmod a+x php-cs-fixer
mv php-cs-fixer /usr/local/bin/php-cs-fixerCopy the code
You can view the composer method on the official website
upgrade
php php-cs-fixer self-updateCopy the code
You can view the composer method on the official website
use
Repair the specified file directly
php php-cs-fixer fix /tmp/ArticlesController.phpCopy the code
Repair all files in the directory
php php-cs-fixer fix /tmpCopy the code
Specify repair specification rules. The default values are PSR1 and PSR2
# PSR2 rules specified PHP PHP - cs - fixer fix/TMP/ArticlesController. PHP - rules = @ PSR2Copy the code
# rules specify multiple PHP PHP - cs - fixer fix/TMP/ArticlesController. PHP - rules = @ Symfony, @ PSR1. @ PSR2Copy the code
The cache. Use cache by default
# do not use the cache - PHP PHP cs - fixer fix/TMP/ArticlesController. - using cache - PHP noCopy the code
Do not actually repair the file, only view the reported differences to be fixed
php php-cs-fixer fix /tmp/ArticlesController.php --dry-run --diffCopy the code
PHP_CodeSniffer (PHP dresser)
The PHP version must be 5.4.0 or greater
You can view the help information by using the -h parameter.
PHP_CodeSniffer in addition to installing, viewing reports, setting coding standards, file repair, etc., as listed below, you can also set the report level, coding, and check JavaScript and CSS issues through setting. Details can be found on the PHP_CodeSniffer WIKI
The installation
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
php phpcs.phar -h
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar
php phpcbf.phar -hCopy the code
PHP_CodeSniffer installation can be viewed by composer
Check the report
# PHPCS specify a single file/TMP/ArticlesController. PHPCopy the code
PHPCS /path/to/codeCopy the code
Print discrepancy report
Print discrepancy report
phpcs --report=diff /tmp/Controllers/ArticlesController.phpCopy the code
Prints the discrepancy report to the specified file
phpcs --report-diff=/tmp/changes.diff /tmp/ArticlesController.phpCopy the code
View the installed coding standards
phpcs -iCopy the code
Specify coding standard
phpcs --standard=PEAR /tmp/ArticlesController.php
phpcs --standard=PEAR,Squiz /tmp/ArticlesController.phpCopy the code
Fix the file using the PSR2 encoding standard
phpcbf -w --standard=PSR2 /tmp/ArticlesController.phpCopy the code
Git Hooks syntax error detection
Git commit: check for syntactic errors in all PHP files.
There are so many things you can do in Git HOOKS, so you can use your imagination to do what you want to do and improve the efficiency of the project.
#! IS_ERROR_MESSAGE=() while read st file do if ['D' == "$st"] then echo $file Continue fi # if the end of the file is not.php, and exit the loop if [[! $file" =~ (\.php$)]] then echo $file continue fi PHP_LINT= 'PHP -l $file' # if [0-eq $?] ERROR_COUNT=${#IS_ERROR_MESSAGE[@]} then echo $PHP_LINT continue fi # count =${#IS_ERROR_MESSAGE[@] IS_ERROR_MESSAGE[${ERROR_COUNT}]=$PHP_LINT done <<EOF `git diff --cached --name-status` EOF if [ -n ${IS_ERROR_MESSAGE}"] then # loop through the error message and specify a red color for ((I =0; i<${#IS_ERROR_MESSAGE[@]}; i++)) do echo -e "\033[31m ${IS_ERROR_MESSAGE[$i]} \033[0m" done exit 1 fi exit 0Copy the code
Git Hooks pre-commit-php-lint address