-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpre-commit-phpcs
More file actions
executable file
·67 lines (61 loc) · 1.54 KB
/
pre-commit-phpcs
File metadata and controls
executable file
·67 lines (61 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#
# check PHP code syntax error and standard with phpcs
# author : star[github.com/star1989]
# date : 2017-02-24
PROJECT=$(git rev-parse --show-toplevel)
cd $PROJECT
SFILES=$(git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\.php)
TMP_DIR=$PROJECT."/tmp"
# Determine if a file list is passed
if [ "$#" -ne 0 ]
then
exit 0
fi
echo "Checking PHP Lint..."
for FILE in $SFILES
do
# echo "php -l -d display_errors=0 ${FILE}"
# echo "git show :$FILE > $TMP_DIR/$FILE"
php -l -d display_errors=0 $FILE
if [ $? != 0 ]
then
echo "Fix the error before commit."
exit 1
fi
FILES="$FILES $PROJECT/$FILE"
done
echo "Checkout report dir..."
if [ -d report ]
then
echo "Delete report dir"
rm -rf report
fi
if [ ! -d report ]
then
echo "Create report dir"
mkdir report
fi
if [ "$FILES" != "" ]
then
echo "Running Code Sniffer & MD..."
TMP_DIR=/tmp/$(uuidgen)
mkdir -p $TMP_DIR
for FILE in $SFILES
do
mkdir -p $TMP_DIR/$(dirname $FILE)
git show :$FILE > $TMP_DIR/$FILE
phpcbf --standard=PSR2 $FILE
phpmd $FILE html cleancode,codesize,design,naming,unusedcode,controversial --suffixes php --ignore-violations-on-exit >> $PROJECT/report/md.html
done
phpcs --standard=PSR2 --encoding=utf-8 -n $TMP_DIR > $PROJECT/report/standard.txt
PHPCS_ERROR=$?
rm -rf $TMP_DIR
if [ $PHPCS_ERROR != 0 ]
then
#echo "Fix the error before commit."
echo "Please look reports.Then fix the errors"
exit 1
fi
fi
exit $?