Skip to content

Instantly share code, notes, and snippets.

@s7anley
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s7anley/9d9cf0152ee1431715a6 to your computer and use it in GitHub Desktop.
Save s7anley/9d9cf0152ee1431715a6 to your computer and use it in GitHub Desktop.
Pre commit php-cs-fixer
#!/bin/bash
PROJECTROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
FIXER=php-cs-fixer.phar
if [ ! -e ${PROJECTROOT}${FIXER} ]; then
echo "PHP-CS-Fixer not available, downloading to ${PROJECTROOT}${FIXER}..."
curl -s http://cs.sensiolabs.org/get/$FIXER > ${PROJECTROOT}${FIXER}
echo ""
fi
git diff --cached --name-only | while read LINE ; do
FILENAME=$(basename "$LINE")
EXTENSION="${FILENAME##*.}"
if [ "$EXTENSION" == "php" ]; then
php ${PROJECTROOT}${FIXER} fix $LINE --level=all --diff --fixers=-phpdoc_params
git add $LINE;
fi;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment