Last active
August 29, 2015 13:56
-
-
Save quickshiftin/8949119 to your computer and use it in GitHub Desktop.
The lint utility you wish `php -l` was out of the box. Lint check multiple PHP files with a single command.
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
function php_lint | |
{ | |
for arg in $(seq $#) | |
do | |
# Use find to iterate over directories recursively | |
if [ -d "${!arg}" ]; then | |
find "${!arg}" -name '*.php' -exec php -l "{}" ";" | |
# Just run normal files and symlinks through php -l individually | |
elif [ -f "${!arg}" -o -h "${!arg}" ]; then | |
php -l "${!arg}" | |
# Skip over anything else | |
else | |
echo 'Skipping bogus argument' 1>&2 | |
fi | |
done | |
} |
The find
will only lint files within a directory one at a time. Something else you might like, which I found pretty cool, would be running the directory segment through xargs
and adding some parallelism. Take a peak at this approach.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function is a drop-in replacement for
php -l
that is 1000x better. It can easily be turned into an executable. It can handle directories, files and any number of arguments. Give it a tryFor the directory searches, the file name extensions are hardcoded to .php. That's just how I roll, but feel free to customize ;)