Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danielcosta
Last active July 19, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielcosta/eb289e7c64a5a24b87437de70f9acdb6 to your computer and use it in GitHub Desktop.
Save danielcosta/eb289e7c64a5a24b87437de70f9acdb6 to your computer and use it in GitHub Desktop.
Lint changed PHP files
#!/usr/bin/env bash
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
ANCESTOR=$(git merge-base $CURRENT_BRANCH master)
OIFS=$IFS
IFS=$'\n' FILES=($(git diff --name-status $ANCESTOR HEAD | grep -E '^[AM].+\.php$' | awk '{print $2}'))
IFS=$OIFS
php-lint.sh "${FILES[@]}"
#!/bin/bash
error=false
while test $# -gt 0; do
current=$1
shift
if [ ! -d $current ] && [ ! -f $current ] ; then
echo "Invalid directory or file: $current"
error=true
continue
fi
for file in `find $current -type f -name "*.php"` ; do
RESULTS=`php -l $file`
if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
echo $RESULTS
error=true
fi
done
done
if [ "$error" = true ] ; then
exit 1
else
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment