Repository navigation
Expand file tree
/
Copy pathrun-phpstan-tests
More file actions
executable file
·72 lines (61 loc) · 2.24 KB
/
Copy pathrun-phpstan-tests
File metadata and controls
executable file
·72 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
EXIT_CODE=0
# 1. Run the static analysis only if a configuration file exists.
if [ -f "phpstan.dist.neon" ] || [ -f "phpstan.neon.dist" ] || [ -f "phpstan.neon" ]
then
vendor/bin/phpstan --memory-limit=2048M analyse "$@" || EXIT_CODE=$?
fi
# 2. Run PHPStan over the PHP blocks in .feature files if the package opted in.
DIR="$(cd "$(dirname "$0")/.." && pwd)"
FEATURE_CONFIG=""
for CANDIDATE in "phpstan-feature-files.neon" "phpstan-feature-files.neon.dist"
do
if [ -f "$CANDIDATE" ]
then
FEATURE_CONFIG="$(pwd)/$CANDIDATE"
break
fi
done
if [ -d "features" ] && [ -n "$FEATURE_CONFIG" ] && [ -f "$DIR/utils/phpstan-feature-files.php" ]
then
TEMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'feature_phpstan')
trap 'rm -rf "$TEMP_DIR"' EXIT HUP INT TERM
# Results are only reported when the extraction they are based on succeeded.
if php "$DIR/utils/phpstan-feature-files.php" extract features "$TEMP_DIR/blocks"
then
{
echo "includes:"
echo " - $DIR/phpstan/feature-files.neon"
echo " - $FEATURE_CONFIG"
# The functions in the `WP_CLI\Utils` namespace are pulled in through the
# `files` autoloader, which does not make them known to PHPStan.
if [ -d "vendor/wp-cli/wp-cli" ]
then
echo "parameters:"
echo " scanDirectories:"
echo " - $(pwd)/vendor/wp-cli/wp-cli"
fi
} > "$TEMP_DIR/phpstan-feature-files.neon"
# Blocks are spread over batches that do not declare the same symbol twice,
# so that PHPStan does not resolve a name to another block's declaration.
for BATCH in "$TEMP_DIR"/blocks/batch*
do
[ -d "$BATCH" ] || continue
vendor/bin/phpstan --memory-limit=2048M analyse \
--configuration="$TEMP_DIR/phpstan-feature-files.neon" \
--error-format=json \
--no-progress \
"$BATCH" > "$TEMP_DIR/$(basename "$BATCH").json" 2>"$TEMP_DIR/$(basename "$BATCH").stderr"
# Anything PHPStan itself has to say goes to the terminal, while its
# findings are reported against the feature files they came from.
if [ -s "$TEMP_DIR/$(basename "$BATCH").stderr" ]
then
cat "$TEMP_DIR/$(basename "$BATCH").stderr" >&2
fi
done
php "$DIR/utils/phpstan-feature-files.php" report "$TEMP_DIR/blocks" "$TEMP_DIR"/batch*.json || EXIT_CODE=$?
else
EXIT_CODE=1
fi
fi
exit $EXIT_CODE