@@ -9,30 +9,57 @@ if [[ "true" == "$CI" ]]; then
99 phpstanNoProgress+=(--no-progress)
1010fi
1111
12- while (( phpStanExitCode > 0 )) ; do
13- # Run PHPStan with tee to capture output to both file and stdout
12+ if [[ " 1" == " ${useJsonOutput:- 0} " ]]; then
13+ # JSON mode: single run, no retry loop, structured output
14+ phpStanJsonFile=" $phpStanLogDir /phpstan.json"
15+
1416 phpNoXdebug -f " $pharDir " /phpstan.phar -- \
1517 analyse ${pathsToCheck[@]} \
1618 -c " $phpstanConfigPath " \
17- ${phpstanNoProgress[@]:- } \
18- 2>&1 | tee " $phpStanLogDir /$phpStanLogFile "
19+ --no-progress \
20+ --error-format=json \
21+ > " $phpStanJsonFile "
22+
23+ phpStanExitCode=$?
1924
20- phpStanExitCode=${PIPESTATUS[0]}
25+ # Output JSON to fd 3 (original stdout, bypassing stderr redirect)
26+ cat " $phpStanJsonFile " >&3
2127
22- # Archive PHPStan log with timestamp - keep last 10 per pattern
23- # Do this BEFORE tryAgainOrAbort so log is archived even on failure (in CI mode)
24- # Uses shared archiveToolLog function from functions.inc.bash
25- archiveToolLog " PHPStan" " $phpStanLogDir " " $phpStanLogFile " " $specifiedPath " " ${pathsToCheck[@]} "
28+ # Archive the JSON log
29+ archiveToolLog " PHPStan" " $phpStanLogDir " " phpstan.json" " $specifiedPath " " ${pathsToCheck[@]} "
2630
27- # exit code 0 = fine, 1 = ran fine but found errors, else it means it crashed
2831 if (( phpStanExitCode > 1 )) ; then
29- printf " \n\n\nPHPStan Crashed!!....\n\nrunning again with debug mode:\nWhere ever it stops is probably a fatal PHP error\n\n"
30- eval phpNoXdebug -f " $pharDir " /phpstan.phar -- analyse $pathsStringArray -c " $phpstanConfigPath " --debug -v
32+ echo " PHPStan crashed (exit code: $phpStanExitCode )" >&2
3133 exit 1
3234 fi
33- if (( phpStanExitCode > 0 )) ; then
34- tryAgainOrAbort " PHPStan"
35- fi
36- done
35+ # Exit code 1 = found errors — expected for JSON consumption, don't retry
36+ else
37+ # Text mode: original behavior with retry loop
38+ while (( phpStanExitCode > 0 )) ; do
39+ # Run PHPStan with tee to capture output to both file and stdout
40+ phpNoXdebug -f " $pharDir " /phpstan.phar -- \
41+ analyse ${pathsToCheck[@]} \
42+ -c " $phpstanConfigPath " \
43+ ${phpstanNoProgress[@]:- } \
44+ 2>&1 | tee " $phpStanLogDir /$phpStanLogFile "
45+
46+ phpStanExitCode=${PIPESTATUS[0]}
47+
48+ # Archive PHPStan log with timestamp - keep last 10 per pattern
49+ # Do this BEFORE tryAgainOrAbort so log is archived even on failure (in CI mode)
50+ # Uses shared archiveToolLog function from functions.inc.bash
51+ archiveToolLog " PHPStan" " $phpStanLogDir " " $phpStanLogFile " " $specifiedPath " " ${pathsToCheck[@]} "
52+
53+ # exit code 0 = fine, 1 = ran fine but found errors, else it means it crashed
54+ if (( phpStanExitCode > 1 )) ; then
55+ printf " \n\n\nPHPStan Crashed!!....\n\nrunning again with debug mode:\nWhere ever it stops is probably a fatal PHP error\n\n"
56+ eval phpNoXdebug -f " $pharDir " /phpstan.phar -- analyse $pathsStringArray -c " $phpstanConfigPath " --debug -v
57+ exit 1
58+ fi
59+ if (( phpStanExitCode > 0 )) ; then
60+ tryAgainOrAbort " PHPStan"
61+ fi
62+ done
63+ fi
3764
3865set -e
0 commit comments