#!/usr/bin/env bash
#
# Lint the PHP files against parse errors.
#
# The find utility recursively descends the directory tree for each path listed.
#
# find . = Start with all files in this package
# -path ./vendor -prune = But remove those in the vendor directory
# -o -path ./bin -prune = And remove those in the bin directory
# -o -path ./.git -prune = And remove those in the .git directory
# -o -name "*.php" = And only consider those with a .php extension
# -exec php -l {} = Run PHP linter on the remaining files
# | grep "^[Parse error|Fatal error]" = Look in the results for any parse or fatal errors.
#
# EXAMPLE TO RUN LOCALLY:
#
#   ./bin/php-lint
#

if find . -path ./vendor -prune -o -path ./bin -prune -o -path ./.git -prune -o -name "*.php" -exec php -l -f {} \; | grep "^[Errors parsing]"; then
    exit 1;
fi
