Created
May 11, 2018 09:06
-
-
Save saystone/6ae86685f34d632c37a98fc4d36b74d2 to your computer and use it in GitHub Desktop.
pre-commit-php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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