Skip to content

Instantly share code, notes, and snippets.

@cakper
Last active April 20, 2017 07:57
Show Gist options
  • Select an option

  • Save cakper/fbfae9e1acc68b1e560b to your computer and use it in GitHub Desktop.

Select an option

Save cakper/fbfae9e1acc68b1e560b to your computer and use it in GitHub Desktop.
GIT pre-commit PHPSpec & PHP-CS-Fixer hook
#!/bin/sh
CWD=$(pwd)
STATUS=0
echo "Running PHPSpec and PHPCS"
if [ -f $CWD/bin/phpspec ]
then
$CWD/bin/phpspec run --quiet
if [ $? -ne 0 ]
then
echo "PHPSpec has failed - commit aborted"
STATUS=1
fi
fi
if [ -f $CWD/bin/php-cs-fixer ]
then
$CWD/bin/php-cs-fixer fix --quiet --dry-run src
if [ $? -ne 0 ]
then
echo "PHPCS for src/ has failed - commit aborted"
STATUS=1
fi
$CWD/bin/php-cs-fixer fix --quiet --fixers=-visibility --dry-run spec
if [ $? -ne 0 ]
then
echo "PHPCS for spec/ has failed - commit aborted"
STATUS=1
fi
$CWD/bin/php-cs-fixer fix --quiet --dry-run features
if [ $? -ne 0 ]
then
echo "PHPCS for features/ has failed - commit aborted"
STATUS=1
fi
fi
exit $STATUS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment