-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpstan.inc.bash
More file actions
executable file
·84 lines (71 loc) · 2.73 KB
/
phpstan.inc.bash
File metadata and controls
executable file
·84 lines (71 loc) · 2.73 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
73
74
75
76
77
78
79
80
81
82
83
84
set +e
phpStanExitCode=99
phpStanLogDir="$varDir/phpstan_logs"
phpStanLogFile="phpstan.log"
mkdir -p "$phpStanLogDir"
# Limit parallel processing to use only half of available CPU threads
# to avoid overwhelming the system (consistent with Rector configuration)
cpuThreads=$(nproc 2>/dev/null || echo 4)
maxProcesses=$(( cpuThreads / 2 ))
if (( maxProcesses < 1 )); then
maxProcesses=1
fi
phpStanParallelConfig="$phpStanLogDir/phpstan-parallel.neon"
cat > "$phpStanParallelConfig" << NEON
includes:
- $phpstanConfigPath
parameters:
parallel:
maximumNumberOfProcesses: $maxProcesses
NEON
phpstanConfigPath="$phpStanParallelConfig"
echo "PHPStan: limiting to $maxProcesses parallel processes (50% of $cpuThreads cores)"
phpstanNoProgress=()
if [[ "true" == "$CI" ]]; then
phpstanNoProgress+=(--no-progress)
fi
if [[ "1" == "${useJsonOutput:-0}" ]]; then
# JSON mode: single run, no retry loop, structured output
phpStanJsonFile="$phpStanLogDir/phpstan.json"
phpNoXdebug -f "$pharDir"/phpstan.phar -- \
analyse ${pathsToCheck[@]} \
-c "$phpstanConfigPath" \
--no-progress \
--error-format=json \
> "$phpStanJsonFile"
phpStanExitCode=$?
# Output JSON to fd 3 (original stdout, bypassing stderr redirect)
cat "$phpStanJsonFile" >&3
# Archive the JSON log
archiveToolLog "PHPStan" "$phpStanLogDir" "phpstan.json" "$specifiedPath" "${pathsToCheck[@]}"
if ((phpStanExitCode > 1)); then
echo "PHPStan crashed (exit code: $phpStanExitCode)" >&2
exit 1
fi
# Exit code 1 = found errors — expected for JSON consumption, don't retry
else
# Text mode: original behavior with retry loop
while ((phpStanExitCode > 0)); do
# Run PHPStan with tee to capture output to both file and stdout
phpNoXdebug -f "$pharDir"/phpstan.phar -- \
analyse ${pathsToCheck[@]} \
-c "$phpstanConfigPath" \
${phpstanNoProgress[@]:-} \
2>&1 | tee "$phpStanLogDir/$phpStanLogFile"
phpStanExitCode=${PIPESTATUS[0]}
# Archive PHPStan log with timestamp - keep last 10 per pattern
# Do this BEFORE tryAgainOrAbort so log is archived even on failure (in CI mode)
# Uses shared archiveToolLog function from functions.inc.bash
archiveToolLog "PHPStan" "$phpStanLogDir" "$phpStanLogFile" "$specifiedPath" "${pathsToCheck[@]}"
#exit code 0 = fine, 1 = ran fine but found errors, else it means it crashed
if ((phpStanExitCode > 1)); then
printf "\n\n\nPHPStan Crashed!!....\n\nrunning again with debug mode:\nWhere ever it stops is probably a fatal PHP error\n\n"
eval phpNoXdebug -f "$pharDir"/phpstan.phar -- analyse $pathsStringArray -c "$phpstanConfigPath" --debug -v
exit 1
fi
if ((phpStanExitCode > 0)); then
tryAgainOrAbort "PHPStan"
fi
done
fi
set -e