1313#
1414# #########
1515
16- GRAY=' \033[0;37m'
17- RED=' \033[0;31m'
18- GREEN=' \033[0;32m'
19-
2016PHPCS_BIN=/usr/bin/phpcs
21- PHPMD_BIN=/usr/bin/phpmd
2217PHPCS_CODING_STANDARD=PEAR
23- PHPMD_OUTPUT_MODE=text
24- PHPMD_PATTERNS=cleancode,codesize,controversial,design,naming,unusedcode
2518PHPCS_IGNORE=
19+ PHPMD_BIN=/usr/bin/phpmd
20+ PHPMD_OUTPUT=text
21+ PHPMD_PATTERNS_LIST=cleancode,codesize,controversial,design,naming,unusedcode
2622TMP_STAGING=" .tmp_staging"
2723
28- # parse config
24+ # Parse config
2925CONFIG_FILE=$( dirname $0 ) /config
3026if [ -e $CONFIG_FILE ]; then
3127 . $CONFIG_FILE
3228fi
3329
34- # simple check if code sniffer is set up correctly
35- if [ ! -x $PHPCS_BIN ]; then
36- echo " PHP CodeSniffer bin not found or executable -> $PHPCS_BIN "
30+ # Simple check if code sniffer is set up correctly
31+ if [ ! -x $PHPCS_BIN ] || [ ! -x $PHPMD_BIN ] ; then
32+ tput setaf 1 ; echo " Executable not found. Check $PHPCS_BIN and $PHPMD_BIN . "
3733 exit 1
3834fi
3935
40- # stolen from template file
36+ # Stolen from template file
4137if git rev-parse --verify HEAD
4238then
4339 against=HEAD
4642 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
4743fi
4844
49- # this is the magic:
50- # retrieve all files in staging area that are added, modified or renamed
45+ # This is the magic:
46+ # Retrieve all files in staging area that are added, modified or renamed
5147# but no deletions etc
5248FILES=$( git diff-index --name-only --cached --diff-filter=ACMR $against -- )
5349
5450if [ " $FILES " == " " ]; then
5551 exit 0
5652fi
5753
58- # create temporary copy of staging area
54+ # Create temporary copy of staging area
5955if [ -e $TMP_STAGING ]; then
6056 rm -rf $TMP_STAGING
6157fi
6258mkdir $TMP_STAGING
6359
64- # match files against whitelist
60+ # Match files against whitelist
6561FILES_TO_CHECK=" "
6662for FILE in $FILES
6763do
@@ -77,7 +73,7 @@ if [ "$FILES_TO_CHECK" == "" ]; then
7773 exit 0
7874fi
7975
80- # execute the code sniffer
76+ # Validate PHP CodeSniffer variables
8177if [ " $PHPCS_IGNORE " != " " ]; then
8278 IGNORE=" --ignore=$PHPCS_IGNORE "
8379else
@@ -102,16 +98,30 @@ else
10298 IGNORE_WARNINGS=" "
10399fi
104100
101+ # Validate PHP Mess Detector variables
102+ if [ " $PHPMD_OUTPUT_MODE " != " " ]; then
103+ PHPMD_OUTPUT=" $PHPMD_OUTPUT_MODE "
104+ else
105+ PHPMD_OUTPUT=" text"
106+ fi
107+
108+ if [ " $PHPMD_PATTERNS " != " " ]; then
109+ PHPMD_PATTERNS_LIST=" $PHPMD_PATTERNS "
110+ else
111+ PHPMD_PATTERNS_LIST=" cleancode"
112+ fi
113+
114+
105115# Copy contents of staged version of files to temporary staging area
106116# because we only want the staged version that will be commited and not
107- # the version in the working directory
117+ # the version in the working directory.
108118STAGED_FILES=" "
109119for FILE in $FILES_TO_CHECK
110120do
111121 ID=$( git diff-index --cached $against $FILE | cut -d " " -f4)
112122
113- # create staged version of file in temporary staging area with the same
114- # path as the original file so that the phpcs ignore filters can be applied
123+ # Create staged version of file in temporary staging area with the same
124+ # path as the original file so that the phpcs ignore filters can be applied.
115125 mkdir -p " $TMP_STAGING /$( dirname $FILE ) "
116126 git cat-file blob $ID > " $TMP_STAGING /$FILE "
117127 STAGED_FILES=" $STAGED_FILES $TMP_STAGING /$FILE "
136146
137147echo " "
138148tput setaf 7; echo " :: PHP Mess Detector inspection :: "
139- PHPMD_OUTPUT=$( $PHPMD_BIN $STAGED_FILES $PHPMD_OUTPUT_MODE $PHPMD_PATTERNS )
149+ PHPMD_OUTPUT=$( $PHPMD_BIN $STAGED_FILES $PHPMD_OUTPUT $PHPMD_PATTERNS_LIST )
140150PHPMD_RETVAL=$?
141151
142152if [ $PHPMD_RETVAL -ne 0 ]; then
152162
153163tput setaf 7;
154164
165+ echo " "
155166exit 0;
0 commit comments