Pre commit hook to check PHP code coverage and code sniffer for Symfony Pre commit hook to check PHP code coverage and code sniffer for Symfony symfony symfony

Pre commit hook to check PHP code coverage and code sniffer for Symfony


If your bash script works as expected, you just need to name it pre-commit and put it in your git hooks: /path/to/repo/.git/hooks. You'll find some sample in this directory.

For more information about git hooks: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

Then, for you code sniffer, I recommend https://github.com/squizlabs/PHP_CodeSniffer.

There is also https://github.com/phpro/grumphp that will do everything for you.


No need to use grumphp when you can easily accomplish it with client side git hooks. Example below runs php-cs-fixer and prevents pushing broken code to github repository when you run git push origin ......

your_project_folder/.git/hooks/pre-push

#!/bin/shif [ -f ./bin/php-cs-fixer ]then    ./bin/php-cs-fixer fix --dry-run --verbose --diff src    if [ $? -ne 0 ]    then        printf "\n\t\033[1;31m[PHP-CS-Fixer] Push Aborted\n\n\033[0m"        return 1    fifi

Grant permissions

chmod +x .git/hooks/pre-push

Test

git push origin .....

See example here.