Skip to content

Instantly share code, notes, and snippets.

@tabuna
Last active May 28, 2018 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabuna/c9c9c6d5f73bb23d5b6c73a2e6cdace5 to your computer and use it in GitHub Desktop.
Save tabuna/c9c9c6d5f73bb23d5b6c73a2e6cdace5 to your computer and use it in GitHub Desktop.
php-cs-fixer pre commit hook
#!/usr/bin/env bash
echo "php-cs-fixer pre commit hook start"
PHP_CS_FIXER="vendor/bin/php-cs-fixer"
HAS_PHP_CS_FIXER=false
if [ -x vendor/bin/php-cs-fixer ]; then
HAS_PHP_CS_FIXER=true
fi
if $HAS_PHP_CS_FIXER; then
git status --porcelain | grep -e '^\(.*\).php$' | cut -c 3- | while read line; do
$PHP_CS_FIXER fix --config .php_cs --verbose "$line";
git add "$line";
done
git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do
$PHP_CS_FIXER fix --config .php_cs --verbose "$line";
git add "$line";
done
else
echo ""
echo "Please install php-cs-fixer, e.g.:"
echo ""
echo " composer require --dev fabpot/php-cs-fixer:dev-master"
echo ""
fi
echo "php-cs-fixer pre commit hook finish"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment