Last active
July 19, 2017 14:31
-
-
Save danielcosta/eb289e7c64a5a24b87437de70f9acdb6 to your computer and use it in GitHub Desktop.
Lint changed PHP files
This file contains hidden or 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
#!/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[@]}" |
This file contains hidden or 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
#!/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