Merge "Add parameter to API modules to apply change tags to log entries"
[lhc/web/wiklou.git] / tests / phan / bin / phan
index 5d42cf5..ad06823 100755 (executable)
@@ -7,12 +7,25 @@ if ! which realpath > /dev/null; then
        }
 fi
 
+if hash php7.0 2>/dev/null; then
+       export PHP="php7.0"
+else
+       export PHP="php"
+fi
+
 # Note that this isn't loaded in via composer because then composer can
 # only be run with php7.0
 if [ ! -f "$PHAN" ]; then
-       echo "The environment variable PHAN must point to the 'phan' file"
-       echo "in a checkout of https://github.com/etsy/phan.git"
-       exit 1
+       # If no PHAN is specified then try to get location from PATH
+       export PHAN="$(which phan)"
+       if [ ! -f "$PHAN" ]; then
+               echo "The environment variable PHAN must point to the 'phan' file"
+               echo "in a checkout of https://github.com/etsy/phan.git"
+               echo "Or phan must be included in your PATH"
+               exit 1
+       fi
+else
+       export PHAN="$PHP $PHAN"
 fi
 
 if [ -z "$MW_INSTALL_PATH" ]; then
@@ -24,7 +37,7 @@ fi
 
 # If the first argument doesn't start with a -, then it's a path
 # to another project (extension, skin, etc.) to analyze
-if [[ "$1" != "-"* ]]; then
+if [[ -n "$1" && "$1" != "-"* ]]; then
        cd $1
        shift
 else
@@ -57,7 +70,7 @@ export RUN="${ISSUES}/issues-${REV}"
 
 # Run the analysis, emitting output to the
 # issues file.
-php7.0 $PHAN \
+$PHAN \
        --project-root-directory "$ROOT" \
        --config-file "$CONFIG_FILE" \
        --output "php://stdout" \