Skip to content

Instantly share code, notes, and snippets.

@halkyon
Last active July 11, 2017 03:42
Show Gist options
  • Save halkyon/38948efc31a88135efb6b4d2ff453633 to your computer and use it in GitHub Desktop.
Save halkyon/38948efc31a88135efb6b4d2ff453633 to your computer and use it in GitHub Desktop.
pre-commit script to run php-cs-fixer against changed PHP scripts
#!/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