Pre-commit hook that supports PHPCS and PHPDOC
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 | |
################################################################ | |
# Pre commit hook for git | |
# | |
# @package: utilities | |
# @subpackage: utilities\git | |
# @author: Aleksey Korzun <al.ko@webfoundation.net> | |
################################################################ | |
# Specify full path to your PHP executable | |
PHP="php" | |
# Specify full path to your PHP Code Sniffer installation | |
PHP_CS="utilities/phpcs.php" | |
# Specify full path to your PHP Documentator installation | |
PHP_DOC="utilities/phpdoc.php" | |
# Extension of your PHP files | |
EXTENSION="\.php"; | |
# PHP Code Sniffer | |
for FILE in `git diff --cached --name-only | grep -i $EXTENSION`; do | |
# Make sure file exists | |
if [ ! -f $FILE ]; then | |
continue | |
fi | |
echo "" | |
echo "Verifying $FILE against internal styling guide..."; | |
$PHP $PHP_CS $FILE | |
if [ $? -eq 1 ]; then | |
exit 1 | |
fi | |
echo "Done"; | |
done | |
# PHP Documentator | |
for FILE in `git diff --cached --name-only | grep -i $EXTENSION`; do | |
# Make sure file exists | |
if [ ! -f $FILE ]; then | |
continue | |
fi | |
echo "" | |
echo "Verifying $FILE against PHP Documentor..."; | |
IFS=$'\n' DATA=( $(PHP $PHP_DOC parse --skip-save -f $FILE) ) | |
if [[ "${#DATA[@]}" -gt 3 ]]; then | |
unset DATA[0] | |
unset DATA[1] | |
unset DATA[2] | |
if [[ "${DATA[3]}" == *"No page-level DocBlock"* ]]; then | |
unset DATA[3] | |
fi | |
if [[ "${#DATA[@]}" -ge 1 ]]; then | |
for line in "${DATA[@]}" | |
do | |
echo $line | |
done | |
exit 1 | |
fi | |
fi | |
echo "Done"; | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment