Last active
January 21, 2016 01:42
-
-
Save bradynpoulsen/d2d33ff01db44a8e6195 to your computer and use it in GitHub Desktop.
Executes PHP CodeSniffer using your project's phpcs.xml settings
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/sh | |
######################################################################################## | |
# # | |
# Created by Bradyn Poulsen # | |
# Install using CURL: # | |
# # | |
# curl -L -o .git/hooks/pre-push https://git.io/vz4TW && chmod +x .git/hooks/pre-push # | |
# # | |
######################################################################################## | |
if [[ -r "$PWD/phpcs.xml" ]]; then | |
phpcsXmlFound='true' | |
else | |
echo "Warning: phpcs.xml could not be found in $PWD...skipping code sniffer check" | |
echo '' | |
exit 0 | |
fi | |
if [[ -x "$PWD/vendor/bin/phpcs" ]]; then | |
phpcsExecFound='true' | |
else | |
echo "Warning: phpcs executable was not found in $PWD/vendor/bin...skipping code sniffer check" | |
echo '' | |
exit 0 | |
fi | |
statefile='.git/push_code_sniffer_state' | |
read details | |
touch $statefile | |
cat $statefile | grep "$details" >/dev/null | |
if [ "$?" == '0' ] && [ "$details" != '' ]; then | |
rm $statefile | |
echo '' | |
echo 'Pushing code with code sniffer errors! Do you even have a soul?' | |
echo '' | |
echo ' __&__' | |
echo ' / \' | |
echo ' | |' | |
echo ' | (o)(o)' | |
echo ' C ,---_)' | |
echo ' | |,___| "I am Homer of the Borg. You will be swatted with a stick. Resistance' | |
echo ' | \__/ is irrelevant. Preparation is irrel...MMMmmm...doughnut!"' | |
echo ' /_____\' | |
echo ' /_____/ \' | |
echo '' | |
else | |
echo 'Checking code sniffer for errors...'; | |
vendor/bin/phpcs --standard=phpcs.xml -n | |
if [ "$?" == '0' ]; then | |
rm $statefile | |
echo '' | |
echo 'Code sniffer passed!' | |
echo '' | |
echo ' * ,MMM8&&&. *' | |
echo ' MMMM88&&&&& .' | |
echo ' MMMM88&&&&&&&' | |
echo ' * MMM88&&&&&&&&' | |
echo ' MMM88&&&&&&&&' | |
echo " 'MMM88&&&&&&'" | |
echo " 'MMM8&&&' * " | |
echo ' |\___/| /\___/\\' | |
echo " ) ( ) ~( . '" | |
echo ' =\ /= =\~ /=' | |
echo ' )===( ) ~ (' | |
echo ' / \ / \' | |
echo ' | | ) ~ (' | |
echo ' / \ / ~ \' | |
echo ' \ / \~ ~/' | |
echo ' _/\_/\_/\__ _/_/\_/\__~__/_/\_/\_/\_/\_/\_' | |
echo ' | | | |( ( | | | )) | | | | | |' | |
echo ' | | | | ) ) | | |//| | | | | | |' | |
echo ' | | | |(_( | | (( | | | | | | |' | |
echo ' | | | | | | | |\)| | | | | | |' | |
echo ' | | | | | | | | | | | | | | |' | |
echo '' | |
else | |
echo "$details" > $statefile | |
echo 'Aborting push! There are code style violations in the project' | |
echo 'Push again to push anyways and then go outsite and pick a stick!' | |
echo '' | |
echo " ___________ ____/--\___" | |
echo " \______ ___) ( _ ____) \"Damn it Jim!," | |
echo " __| |____/ / \`--' I'm a programmer not a Doctor!\"" | |
echo " ) \`|=(-" | |
echo " \-----------'" | |
echo '' | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment