13
13
#
14
14
# #########
15
15
16
- GRAY=' \033[0;37m'
17
- RED=' \033[0;31m'
18
- GREEN=' \033[0;32m'
19
-
20
16
PHPCS_BIN=/usr/bin/phpcs
21
- PHPMD_BIN=/usr/bin/phpmd
22
17
PHPCS_CODING_STANDARD=PEAR
23
- PHPMD_OUTPUT_MODE=text
24
- PHPMD_PATTERNS=cleancode,codesize,controversial,design,naming,unusedcode
25
18
PHPCS_IGNORE=
19
+ PHPMD_BIN=/usr/bin/phpmd
20
+ PHPMD_OUTPUT=text
21
+ PHPMD_PATTERNS_LIST=cleancode,codesize,controversial,design,naming,unusedcode
26
22
TMP_STAGING=" .tmp_staging"
27
23
28
- # parse config
24
+ # Parse config
29
25
CONFIG_FILE=$( dirname $0 ) /config
30
26
if [ -e $CONFIG_FILE ]; then
31
27
. $CONFIG_FILE
32
28
fi
33
29
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 . "
37
33
exit 1
38
34
fi
39
35
40
- # stolen from template file
36
+ # Stolen from template file
41
37
if git rev-parse --verify HEAD
42
38
then
43
39
against=HEAD
46
42
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
47
43
fi
48
44
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
51
47
# but no deletions etc
52
48
FILES=$( git diff-index --name-only --cached --diff-filter=ACMR $against -- )
53
49
54
50
if [ " $FILES " == " " ]; then
55
51
exit 0
56
52
fi
57
53
58
- # create temporary copy of staging area
54
+ # Create temporary copy of staging area
59
55
if [ -e $TMP_STAGING ]; then
60
56
rm -rf $TMP_STAGING
61
57
fi
62
58
mkdir $TMP_STAGING
63
59
64
- # match files against whitelist
60
+ # Match files against whitelist
65
61
FILES_TO_CHECK=" "
66
62
for FILE in $FILES
67
63
do
@@ -77,7 +73,7 @@ if [ "$FILES_TO_CHECK" == "" ]; then
77
73
exit 0
78
74
fi
79
75
80
- # execute the code sniffer
76
+ # Validate PHP CodeSniffer variables
81
77
if [ " $PHPCS_IGNORE " != " " ]; then
82
78
IGNORE=" --ignore=$PHPCS_IGNORE "
83
79
else
@@ -102,16 +98,30 @@ else
102
98
IGNORE_WARNINGS=" "
103
99
fi
104
100
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
+
105
115
# Copy contents of staged version of files to temporary staging area
106
116
# 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.
108
118
STAGED_FILES=" "
109
119
for FILE in $FILES_TO_CHECK
110
120
do
111
121
ID=$( git diff-index --cached $against $FILE | cut -d " " -f4)
112
122
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.
115
125
mkdir -p " $TMP_STAGING /$( dirname $FILE ) "
116
126
git cat-file blob $ID > " $TMP_STAGING /$FILE "
117
127
STAGED_FILES=" $STAGED_FILES $TMP_STAGING /$FILE "
136
146
137
147
echo " "
138
148
tput 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 )
140
150
PHPMD_RETVAL=$?
141
151
142
152
if [ $PHPMD_RETVAL -ne 0 ]; then
152
162
153
163
tput setaf 7;
154
164
165
+ echo " "
155
166
exit 0;
0 commit comments