Merge "Add urlencode for URL encoding of lang values"
[lhc/web/wiklou.git] / tests / phan / bin / phan
1 #!/bin/bash
2
3 # mediawiki-vagrant installs dont have realpath by default
4 if ! which realpath > /dev/null; then
5 realpath() {
6 php -r "echo realpath('$*');"
7 }
8 fi
9
10 if hash php7.0 2>/dev/null; then
11 export PHP="php7.0"
12 else
13 export PHP="php"
14 fi
15
16 # Note that this isn't loaded in via composer because then composer can
17 # only be run with php7.0
18 if [ ! -f "$PHAN" ]; then
19 # If no PHAN is specified then try to get location from PATH
20 export PHAN="$(which phan)"
21 if [ ! -f "$PHAN" ]; then
22 echo "The environment variable PHAN must point to the 'phan' file"
23 echo "in a checkout of https://github.com/etsy/phan.git"
24 echo "Or phan must be included in your PATH"
25 exit 1
26 fi
27 else
28 export PHAN="$PHP $PHAN"
29 fi
30
31 if [ -z "$MW_INSTALL_PATH" ]; then
32 # Figure out where mediawiki is based on the location of this script
33 pushd "$(dirname "$0")" > /dev/null
34 export MW_INSTALL_PATH="$(git rev-parse --show-toplevel)"
35 popd >/dev/null
36 fi
37
38 # If the first argument doesn't start with a -, then it's a path
39 # to another project (extension, skin, etc.) to analyze
40 if [[ -n "$1" && "$1" != "-"* ]]; then
41 cd $1
42 shift
43 else
44 cd "$(dirname "$0")"
45 fi
46
47 # Root directory of project
48 export ROOT="$(git rev-parse --show-toplevel)"
49
50 # Go to the root of this git repo
51 cd "$ROOT"
52
53 export CONFIG_FILE="$ROOT/tests/phan/config.php"
54 if [ ! -f "$CONFIG_FILE" ]; then
55 echo "Could not find a phan config file to apply in"
56 echo "$CONFIG_FILE"
57 exit 1
58 fi
59
60 # Phan's issues directory
61 export ISSUES="${ROOT}/tests/phan/issues"
62 mkdir -p "$ISSUES"
63
64 # Get the current hash of HEAD
65 export REV="$(git rev-parse HEAD)"
66
67 # Destination for issues found
68 export RUN="${ISSUES}/issues-${REV}"
69
70
71 # Run the analysis, emitting output to the
72 # issues file.
73 $PHAN \
74 --project-root-directory "$ROOT" \
75 --config-file "$CONFIG_FILE" \
76 --output "php://stdout" \
77 "${@}" \
78 | php "$MW_INSTALL_PATH/tests/phan/bin/postprocess-phan.php" "${@}" \
79 > $RUN
80
81 EXIT_CODE="$?"
82
83 # Re-link the latest file
84 rm -f "${ISSUES}/latest"
85 ln -s "${RUN}" "${ISSUES}/latest"
86
87 # Output any issues that were found
88 cat "${RUN}"
89
90 exit $EXIT_CODE