Skip to content

Instantly share code, notes, and snippets.

@boompig
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boompig/de3e68bebf299e088ccb to your computer and use it in GitHub Desktop.
Save boompig/de3e68bebf299e088ccb to your computer and use it in GitHub Desktop.
#!/bin/bash
# Make sure all of the PHP files in the given directory compile
function verify_php {
for f in "$1"/*
do
item=$(echo "$f" | grep -o "\.php")
st2=$?
if [ -d "$f" ]
then
check_php "$f"
elif [ $st2 -eq 0 ]
then
error_msg=$(php -l "$f")
status=$?
if [ $status -ne 0 ]
then
exitStatus=$status
echo $error_msg>&2
fi
fi
done
}
# Make sure all PHP files that are modified in latest commit, can compile
function verify_modified_php_files {
git status --porcelain | sed s/'^M '//g | grep '\.php' | while read file
do
error_msg=$(php -l "$file")
status=$?
if [ $status -ne 0 ]
then
echo $error_msg
exit_status=$status
fi
done
}
exitStatus=0
verify_modified_php_files
#verify_php_files "application/models"
#verify_php_files "application/controllers"
#verify_php_files "application/views"
if [ $exitStatus -eq 0 ]
then
echo "[SUMMARY] no syntax errors"
else
echo "[SUMMARY] found syntax errors"
fi
exit $exitStatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment