Skip to content

Instantly share code, notes, and snippets.

@carlosas
Last active September 24, 2020 10:57
Show Gist options
  • Save carlosas/36206cd95354245836226a9b3bb2a947 to your computer and use it in GitHub Desktop.
Save carlosas/36206cd95354245836226a9b3bb2a947 to your computer and use it in GitHub Desktop.
# PHP Architecture Tester pre-commit hook for git
#
# @author Carlos Alandete <carlos.alandete@gmail.com>
#
STAGED_FILES_PHP=$(git diff --cached --name-only --diff-filter=ACM | grep '^src.*\.php\?$')
if [[ "$STAGED_FILES_PHP" == "" ]]; then
printf "\033[1;32mNo files that could affect PHP Architecture Tester\033[0m\n\n"
exit 0
fi
PHPAT="$(git rev-parse --show-toplevel)/vendor/bin/phpat"
if [[ ! -x "$PHPAT" ]]; then
printf "\033[41mPlease install PHP Architecture Tester\033[0m\n"
exit 1
fi
cp phpat.yml tmp_phpat.yml
PREFIX_TO_REMOVE="src/"
while IFS= read -r file ; do
echo " - ${file#$PREFIX_TO_REMOVE}" >> tmp_phpat.yml
done <<< "$STAGED_FILES_PHP"
vendor/bin/phpat tmp_phpat.yml
exit_status=$?
if [[ $exit_status == 0 ]]; then
printf "\n\033[1;32mPHP Architecture Tester Passed\033[0m\n\n"
else
printf "\n\033[1;31mPHP Architecture Tester Failed\033[0m\n\n"
fi
rm tmp_phpat.yml
exit $exit_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment