46 lines
916 B
Bash
Executable File
46 lines
916 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -o nounset
|
|
|
|
# Lint check all PHP files recursively, call with ./test.sh .
|
|
|
|
if [ -z "$1" ] ; then
|
|
printf 'Usage: %s ...\n' "$(basename "$0")"
|
|
exit 1
|
|
fi
|
|
|
|
ERROR=false
|
|
SAVEIFS=$IFS
|
|
IFS=$'\n'
|
|
while test $# -gt 0; do
|
|
CURRENT=${1%/}
|
|
shift
|
|
|
|
if [ ! -f $CURRENT ] && [ ! -d $CURRENT ] ; then
|
|
echo "$CURRENT cannot be found"
|
|
ERROR=true
|
|
continue
|
|
fi
|
|
|
|
for FILE in $(find $CURRENT -type f -name "*.php") ; do
|
|
OUTPUT=$(php -l "$FILE" 2> /dev/null)
|
|
|
|
# Remove blank lines from the `php -l` output
|
|
OUTPUT=$(echo -e "$OUTPUT" | awk 'NF')
|
|
|
|
if [ "$OUTPUT" != "No syntax errors detected in $FILE" ] ; then
|
|
echo -e "$FILE:"
|
|
echo -e " ${OUTPUT//$'\n'/\\n }\n"
|
|
ERROR=true
|
|
fi
|
|
done
|
|
done
|
|
|
|
IFS=$SAVEIFS
|
|
|
|
if [ "$ERROR" = true ] ; then
|
|
exit 1
|
|
fi
|
|
|
|
echo "No syntax errors found."
|
|
exit 0
|