Last active
September 13, 2018 12:56
-
-
Save anwinged/7cad65afc347b081706a52c336f4acd9 to your computer and use it in GitHub Desktop.
Format changed files with php-cs-fixer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eux | |
# Executable directories | |
PATH=bin:tools:${PATH} | |
# Executable | |
fixer_command=php-cs-fixer | |
if command -v php-cs-fixer.sh >/dev/null | |
then | |
fixer_command=php-cs-fixer.sh | |
fi | |
# Options | |
set -- \ | |
--path-mode=intersection \ | |
--verbose \ | |
"$@" | |
if test -r .php_cs | |
then | |
set -- --config=.php_cs "$@" | |
else | |
if test -r .php_cs.dist | |
then | |
set -- --config=.php_cs.dist "$@" | |
fi | |
fi | |
# Changed files | |
changed_files=$(git diff --diff-filter=d --name-only | grep "\\.php$") | |
# Run! | |
${fixer_command} fix "$@" ${changed_files} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment