Last active
July 11, 2017 03:42
-
-
Save halkyon/38948efc31a88135efb6b4d2ff453633 to your computer and use it in GitHub Desktop.
pre-commit script to run php-cs-fixer against changed PHP scripts
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
#!/bin/bash | |
if [ ! -f .php_cs ]; then | |
if [ ! -f .php_cs.dist ]; then | |
exit | |
fi | |
fi | |
EXECUTABLE_NAME="php-cs-fixer" | |
LOCATIONS=( | |
"vendor/bin/$EXECUTABLE_NAME" | |
"../vendor/bin/$EXECUTABLE_NAME" | |
`which $EXECUTABLE_NAME` | |
) | |
for location in ${LOCATIONS[*]}; do | |
if [ -x "$location" ]; then | |
EXECUTABLE=$location | |
break | |
fi | |
done | |
if [ ! -x "$EXECUTABLE" ]; then | |
exit | |
fi | |
git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do | |
$EXECUTABLE fix -v $line | |
git add $line | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment