Created
November 16, 2015 20:27
-
-
Save tburry/53b374492b24beae1b0b to your computer and use it in GitHub Desktop.
Lint a directory tree of PHP files.
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 | |
me=`basename $0` | |
if [ $# -lt 1 ]; then | |
echo "Usage: $me [-q] <folder>" | |
exit 1; | |
fi | |
quick=false | |
if [ "$1" = "-q" ]; then | |
quick=true | |
dir=$2 | |
else | |
dir=$1 | |
fi | |
if [ ! -d "$dir" ]; then | |
echo "No such folder: $dir" | |
exit 1; | |
fi | |
echo "Checking syntax for php files in '$dir'" | |
if [ "$quick" = true ]; then | |
echo "Quick mode is enabled. Execution will stop if an error is found." | |
fi | |
errored=false | |
for file in `find $dir -type f -regex ".*\.php" | grep php` | |
do | |
out=`php -l $file` | |
code=$? | |
if [ ! $code -eq 0 ]; then | |
echo $out; | |
errored=true | |
if [ "$quick" = true ]; then | |
exit 1; | |
fi | |
fi | |
done | |
if [ "$errored" = true ]; then | |
echo "PHP files in '$dir' contain syntax errors." | |
exit 1; | |
fi | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment