forked from nemiah/phpFinTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csfixer-check.sh
executable file
·36 lines (31 loc) · 1.35 KB
/
csfixer-check.sh
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
#!/bin/bash
#
# When this is run as part of a Travis test for a pull request, then it ensures that none of the touched files has any
# PHP CS Fixer warnings.
# From: https://github.com/FriendsOfPHP/PHP-CS-Fixer#using-php-cs-fixer-on-ci
if [ -z "$TRAVIS_COMMIT_RANGE" ]
then
# TRAVIS_COMMIT_RANGE "is empty for builds triggered by the initial commit of a new branch"
# From: https://docs.travis-ci.com/user/environment-variables/
echo "Variable TRAVIS_COMMIT_RANGE not set, falling back to full git diff"
TRAVIS_COMMIT_RANGE=.
fi
IFS='
'
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "$TRAVIS_COMMIT_RANGE")
if [ "$?" -ne "0" ]
then
echo "Error: git diff response code > 0, aborting"
exit 1
fi
if [ -z "${CHANGED_FILES}" ]
then
echo "0 changed files found, exiting"
exit 0
fi
# February 2022: PHP CS FIXER is currently not PHP 8.1 compatible:
# "you may experience code modified in a wrong way"
# "To ignore this requirement please set `PHP_CS_FIXER_IGNORE_ENV`."
export PHP_CS_FIXER_IGNORE_ENV="1"
if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php_cs(\\.dist)?|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php -v --dry-run --stop-on-violation --using-cache=no ${EXTRA_ARGS} || (echo "php-cs-fixer failed" && exit 1)