Skip to content

Instantly share code, notes, and snippets.

@saystone
Created May 11, 2018 09:06
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 saystone/6ae86685f34d632c37a98fc4d36b74d2 to your computer and use it in GitHub Desktop.
Save saystone/6ae86685f34d632c37a98fc4d36b74d2 to your computer and use it in GitHub Desktop.
pre-commit-php
#!/usr/bin/env bash
git diff --cached --name-status | while read status file; do
if [ $status == "D" ]; then continue; fi
echo "processing: $file"
if [[ $file =~ \.php$ ]]; then
if ! php -l $file; then
echo "PHP syntax check failed for file: $file"
exit 1
fi
php /usr/local/bin/php-cs-fixer fix $file --rules=@PSR2
if [ ! $? -eq 0 ]; then
echo "PHP-CS-Fixer failed."
exit 1
fi
git add $file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment