-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathpre-commit
78 lines (62 loc) · 1.97 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php$`
# Determine if a file list is passed
if [ "$#" -eq 1 ]; then
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}
echo "Starting CodeIgniter precommit..."
if [ "$SFILES" != "" ]; then
echo "Linting PHP code..."
for FILE in $SFILES; do
php -l -d display_errors=0 "$PROJECT/$FILE"
if [ $? != 0 ]; then
echo "Fix the error(s) before commit."
exit 1
fi
FILES="$FILES $FILE"
done
fi
if [ "$FILES" != "" ]; then
echo "Running PHPStan..."
# Run on whole codebase
if [ -d /proc/cygdrive ]; then
./vendor/bin/phpstan analyse
else
php ./vendor/bin/phpstan analyse
fi
if [ $? != 0 ]; then
echo "Fix the phpstan error(s) before commit."
exit 1
fi
fi
if [ "$FILES" != "" ]; then
echo "Running PHP CS Fixer..."
# Run on whole codebase to skip on unnecessary filtering
# Run first on app, admin, public
if [ -d /proc/cygdrive ]; then
./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff --config=.no-header.php-cs-fixer.dist.php
else
php ./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff --config=.no-header.php-cs-fixer.dist.php
fi
if [ $? != 0 ]; then
echo "Files in app, admin, or public are not following the coding standards. Please fix them before commit."
exit 1
fi
# Next, run on system, tests, utils, and root PHP files
if [ -d /proc/cygdrive ]; then
./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
else
php ./vendor/bin/php-cs-fixer fix --verbose --dry-run --diff
fi
if [ $? != 0 ]; then
echo "Files in system, tests, utils, or root are not following the coding standards. Please fix them before commit."
exit 1
fi
fi
exit $?