Skip to content

Instantly share code, notes, and snippets.

@quickshiftin
Last active August 29, 2015 13:56
Show Gist options
  • Save quickshiftin/8949119 to your computer and use it in GitHub Desktop.
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.
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
}
@quickshiftin
Copy link
Author

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 try

php_lint file1.php directory-with-php-files symlink.php

For the directory searches, the file name extensions are hardcoded to .php. That's just how I roll, but feel free to customize ;)

@quickshiftin
Copy link
Author

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