Environment: CentOs 6.7
Language: PHP5.4
Php_codesniffer:https://github.com/phpdragon/php_codesniffer
Local code detection See this article: http://www.cnblogs.com/phpdragon/p/5199011.html
1. Download the code from GitHub and unzip it into the/home/hg/php_codesniffer/directory.
Copy the CodeSniffer.conf.dist file as codesniffer.conf and adjust the contents as follows:
<? $phpCodeSnifferConfigarray ( ' php_path ' = '/usr/bin/php ', ' Default_standard ' + ' Phpdragon ', ' report_format ' = ' summary ', ' show_warnings ' = ' 0 ', ' Show_ Progress ' + ' 1 ', ' report_width ' = ' + ','?>
2. Edit the code base/.HG/HGRC file where the code base resides.
3. Add the following nodes.
=/home/hg/php_codesniffer/scripts/hg_pretxnchangegroup_hook. SH
4. Give the script executable permissions chmod a+x.
chmod /home/hg/php_codesniffer/scripts/hg_pretxnchangegroup_hook.sh
5. After configuration, submit the code test:
========================================================= The following is the description of the hook ============================================ ================
1. There are two audit standards:
One is full-volume detection, but allows code to be submitted,
One is a mandatory specification, which is the judgment to decide whether to allow push.
If you find that the code cannot be submitted, click View Log and the log will indicate why the code cannot be submitted.
2. The code detection prompt text format is as follows:
==========================starting PHP Syntax check==========================
Recommended specification, detection of error notification content
=========================force Check PHP Code syntax=========================
Mandatory requirements of the specification, detection error prompt content
===============================================================================
3. Error content to =========================force Check PHP code syntax========================= marked as the beginning, the above content is recommended specification detection error prompt.
This is an error and requires an inspection code:
File:/tmp/php_syntax_files.xxxxx/src/server/userxxxxxxage_update_service.php//Indicates a path to the document that does not conform to the specification, then the actual address is the project path/src/ server/userxxxxxxage_update_service.php
Please follow the instructions below to make the appropriate code adjustments according to the cause of the problem .
Here are the push success tips:
Hook code:
1#!/bin/Bash2 3 ############################################4#1. Edit the code library where the code base/.hg/HGRC] File5#2. Add the following node6 # [Hooks]7# Pretxnchangegroup =/home/hg/php_codesniffer/scripts/hg_pretxnchangegroup_hook.SH8 #9#3. Give the script executable permissionschmodA +xTen # above One ############################################ A - Echo-E"\n==========================starting PHP Syntax check==========================\n" - the#在/Create temp directory under TMP directory -Temp_dir= 'mktemp-DT Php_syntax_files. XXXXXX ' - - #临时测试 +#TEMP_DIR ="/tmp/test/" -#HG_NODE ="d0a1ccf22a26dfe62ae1db932dcc4972509b8f0b" + Ahg_bin="/USR/BIN/HG" atCheck_cmd="/usr/bin/php/home/hg/php_codesniffer/scripts/phpcs--standard=phpdragon--tab-width=4--extensions=php $TEMP _ DIR" -Force_check_cmd="/usr/bin/php/home/hg/php_codesniffer/scripts/phpcs--standard=phpdragonforce--tab-width=4--extensions=php $ Temp_dir" - - #输出临时目录 - Echo "Temp dir:"$TEMP _dir - in #导出当前至最新 -#hg archive-r $HG _node:tip-t files/tmp/Test to #导出当前 +#hg archive-r $HG _node-t files/tmp/Test - #全量导出 the#hg archive-r tip-t files/tmp/Test * #导出修改部分的代码 $ Echo$HG _bin"archive-i \ "set:added () or modified () \"-R"$HG _node": tip-t Files"$TEMP _dirPanax Notoginseng$HG _bin Archive-i"set:added () or modified ()"-R $HG _node:tip-t files $TEMP _dir - the #检测代码, Output hints + Echo "$CHECK _cmd" A $CHECK _cmd the + Echo-E"\n\n\n\n=========================force Check PHP Code syntax=========================\n" - $ #强制检测代码 $ Echo "$FORCE _check_cmd" -test_syntax=' $FORCE _check_cmd ' - Echo-E"$TEST _syntax" the - #删除目录Wuyi Echo "RM-RF"$TEMP _dir the RM-rf"$TEMP _dir" - Wu if["0"=="${test_syntax}"] || [""=="${test_syntax}"]; Then - Echo-E"\n\nthrough code detection, allowed to push! Push successfully!" About Echo-E"\n===============================================================================\n\n" $Exit0 - fi - - Echo-E"\n\nserver detected The code has a problem and check to submit the push again!" A Echo-E"\n===============================================================================\n\n" +Exit1
Php_codesniffer HG Service-side Deployment Chapter