@@ -4,49 +4,75 @@ PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
4
4
STAGED_FILES_CMD=` git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\ .php$`
5
5
6
6
# Determine if a file list is passed
7
- if [ " $# " -eq 1 ]
8
- then
7
+ if [ " $# " -eq 1 ]; then
9
8
oIFS=$IFS
10
9
IFS='
11
10
'
12
11
SFILES=" $1 "
13
12
IFS=$oIFS
14
13
fi
14
+
15
15
SFILES=${SFILES:- $STAGED_FILES_CMD }
16
16
17
17
echo " Starting CodeIgniter precommit..."
18
18
19
- if [ " $SFILES " != " " ]
20
- then
19
+ if [ " $SFILES " != " " ]; then
21
20
echo " Linting PHP code..."
22
- for FILE in $SFILES
23
- do
21
+ for FILE in $SFILES ; do
24
22
php -l -d display_errors=0 " $PROJECT /$FILE "
25
- if [ $? != 0 ]
26
- then
23
+
24
+ if [ $? != 0 ] ; then
27
25
echo " Fix the error(s) before commit."
28
26
exit 1
29
27
fi
28
+
30
29
FILES=" $FILES $FILE "
31
30
done
32
31
fi
33
32
34
- if [ " $FILES " != " " ]
35
- then
33
+ if [ " $FILES " != " " ]; then
36
34
echo " Running PHPStan..."
35
+
37
36
# Run on whole codebase
38
- if [ -d /proc/cygdrive ]
39
- then
37
+ if [ -d /proc/cygdrive ]; then
40
38
./vendor/bin/phpstan analyse
41
39
else
42
40
php ./vendor/bin/phpstan analyse
43
41
fi
44
42
45
- if [ $? != 0 ]
46
- then
43
+ if [ $? != 0 ]; then
47
44
echo " Fix the phpstan error(s) before commit."
48
45
exit 1
49
46
fi
50
47
fi
51
48
49
+ if [ " $FILES " != " " ]; then
50
+ echo " Running PHP CS Fixer..."
51
+
52
+ # Run on whole codebase to skip on unnecessary filtering
53
+ # Run first on app, admin, public
54
+ if [ -d /proc/cygdrive ]; then
55
+ ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no --diff --config=.no-header.php-cs-fixer.dist.php
56
+ else
57
+ php ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no --diff --config=.no-header.php-cs-fixer.dist.php
58
+ fi
59
+
60
+ if [ $? != 0 ]; then
61
+ echo " Files in app, admin, or public are not following the coding standards. Please fix them before commit."
62
+ exit 1
63
+ fi
64
+
65
+ # Next, run on system, tests, utils, and root PHP files
66
+ if [ -d /proc/cygdrive ]; then
67
+ ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no --diff
68
+ else
69
+ php ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no --diff
70
+ fi
71
+
72
+ if [ $? != 0]; then
73
+ echo " Files in system, tests, utils, or root are not following the coding standards. Please fix them before commit."
74
+ exit 1
75
+ fi
76
+ fi
77
+
52
78
exit $?
0 commit comments