Created
January 23, 2017 11:00
-
-
Save davidromani/9fa1c32fcd805a098403a60995aec595 to your computer and use it in GitHub Desktop.
Apply PHP CS fixer Symfony rules in Githook pre-commit
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
#!/bin/bash | |
if [ -x "$(command -v php-cs-fixer)" ]; then | |
FILES=`git diff --name-only` | |
printf '%s\n' "$FILES" | while IFS= read -r FILE | |
do | |
if [[ $FILE == "src/"* ]]; then | |
php-cs-fixer fix "$FILE" --rules=@Symfony | |
# git add "$FILE" | |
fi | |
done | |
FILES=`git diff --name-only --staged` | |
printf '%s\n' "$FILES" | while IFS= read -r FILE | |
do | |
if [[ $FILE == "src/"* ]]; then | |
php-cs-fixer fix "$FILE" --rules=@Symfony | |
git add "$FILE" | |
fi | |
done | |
else | |
echo "Unable to find php-cs-fixer command. Please, check https://github.com/FriendsOfPHP/PHP-CS-Fixer to install it globally (manual) in your system." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Git hook applies a PHP CS Fixer with Symfony rules only in PHP files under "src" directory. Finally, you must execute* this symlink command under project root dir.
*In this case we placed this script under app/Resources/githooks directory