-
Notifications
You must be signed in to change notification settings - Fork 1
/
pre-commit
executable file
·44 lines (37 loc) · 1.04 KB
/
pre-commit
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
#!/bin/sh
# Execute PHP linting tools
# Checks wether ./vendor/bin/phpcs is available before executing
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php$`
if [ "$FILES" != "" ]
then
#echo "Checking PHP Lint..."
for FILE in "${FILES[@]}"
do
php -l -d display_errors=0 $PROJECT/$FILE
if [ $? != 0 ]
then
echo "Fix the error before commit."
exit 1
fi
FILES="$FILES $PROJECT/$FILE"
done
# Determine wether this project contains phpcs
if [ ! -f ./vendor/bin/phpcs ]
then
exit 0
fi
STANDARDS_FILE=""
if [ -f ./vendor/grrr-amsterdam/garp3/phpcs.xml ]
then
STANDARDS_FILE="./vendor/grrr-amsterdam/garp3/phpcs.xml"
fi
#echo "Running Code Sniffer..."
./vendor/bin/phpcs --standard=$STANDARDS_FILE --colors --encoding=utf-8 -n -p $FILES
if [ $? != 0 ]
then
echo "Fix the error before commit."
exit 1
fi
fi
exit $?