Skip to content

Instantly share code, notes, and snippets.

@phcorp
Last active June 17, 2017 00:08
Show Gist options
  • Save phcorp/9127393efc06998cac17ef2c868bdf54 to your computer and use it in GitHub Desktop.
Save phcorp/9127393efc06998cac17ef2c868bdf54 to your computer and use it in GitHub Desktop.
php-cs-fixer pre-commit hook
#!/bin/sh
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/"
PHP_CS_FIXER="bin/php-cs-fixer"
if [ -x $PHP_CS_FIXER ]; then
git status --porcelain | grep -e '^ [AM] \(src\/.*\)\.php' | cut -c 4- | while read line; do
$PHP_CS_FIXER fix "$line" --level=symfony --verbose;
git add "$line";
done
else
echo ""
echo "Please install php-cs-fixer, e.g.:"
echo ""
echo " composer require --dev friendsofphp/php-cs-fixer"
echo ""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment