-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
54 lines (42 loc) · 1.43 KB
/
pre-commit
File metadata and controls
54 lines (42 loc) · 1.43 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
#!/usr/bin/env bash
NC="\033[0m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
function __run() #(step, name, cmd)
{
local color output exitcode
printf "${YELLOW}[%s]${NC} %-20s" "$1" "$2"
output=$(eval "$3" 2>&1)
exitcode=$?
if [[ 0 == $exitcode || 130 == $exitcode ]]; then
echo -e "${GREEN}[PASS]${NC}"
else
echo -e "${RED}[ERROR]${NC}\n\n$output"
exit 1
fi
}
MODIFIED="git diff --diff-filter=M --name-only --cached | grep \".php$\""
IGNORE="resources/lang,resources/views,bootstrap/helpers,database/migrations,bin,.md,*.css,*.js,*.txt"
PHP_BIN=0
PHPCS_BIN=1
PHPSTAN_BIN=0
if [ ! -n "$PHP_BIN" ] || [ "$PHP_BIN" == 1 ]; then
PHP_BIN="php"
fi;
if [ ! -n "$PHPCS_BIN" ] || [ "$PHPCS_BIN" == 1 ]; then
PHPCS_BIN="$PWD/src/vendor/bin/phpcs"
PHPCS_CODESTD="$PWD/src/vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml"
fi;
if [ ! -n "$PHPSTAN_BIN" ] || [ "$PHPCS_BIN" == 1 ]; then
PHPSTAN_BIN="$PWD/src/vendor/bin/phpstan"
fi;
if command -v $PHP_BIN &> /dev/null; then
__run "*" "php lint..." "${MODIFIED} | xargs -r ${PHP_BIN} -l"
fi;
if command -v $PHPCS_BIN &> /dev/null; then
__run "*" "code sniffer..." "${MODIFIED} | xargs -r ${PHPCS_BIN} --report=code --colors --report-width=80 --standard=${PHPCS_CODESTD} --ignore=${IGNORE}"
fi;
if command -v $PHPSTAN_BIN &> /dev/null; then
__run "*" "phpstan..." "${MODIFIED} | xargs -r ${PHPSTAN_BIN} analyse"
fi;