Skip to content

Instantly share code, notes, and snippets.

@kckrinke
Created October 24, 2016 17:58
Show Gist options
  • Save kckrinke/b268f3ce827772850de0bfb69f67925a to your computer and use it in GitHub Desktop.
Save kckrinke/b268f3ce827772850de0bfb69f67925a to your computer and use it in GitHub Desktop.
Check php source files for syntax errors
#!/bin/bash
function lint_check () {
result=`php -l "$1" 2>&1`
if [ $? -ne 0 ]
then
echo "ERROR: php -l \"$1\""
echo "${result}"
return $?
fi
return 0
}
echo "$@" | egrep -q '(\-h|\-\-help)\s+?'
if [ $? -eq 0 -o $# -eq 0 ]
then
echo "usage: $(basename $0) /path/or/file [...]"
exit 1
fi
while [ $# -gt 0 ]
do
tgt="$1"
if [ -d "${tgt}" ]
then
find "${tgt}" -type f -name "*.php" \
| while read src
do
lint_check "${src}"
done
elif [ -f "${tgt}" ]
then
lint_check "${tgt}"
else
echo "Not a file or directory: ${tgt}"
fi
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment