File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change 6363 @unlink ($ rulesFile );
6464}
6565
66- /* ---------- 8. Parse JSON output ---------- */
67- if ($ pmdRaw === null || $ pmdRaw === '' ) {
68- echo json_encode (['violations ' => [], 'debug ' => 'PMD returned no data ' ]);
66+ /* ---------- 8. Extract JSON from raw output (strip warnings) ---------- */
67+ $ jsonStart = strpos ($ pmdRaw , '{ ' );
68+ if ($ jsonStart === false ) {
69+ http_response_code (500 );
70+ echo json_encode (['error ' => 'No JSON found in PMD output ' , 'raw ' => $ pmdRaw ]);
6971 exit ;
7072}
7173
72- $ pmdJson = json_decode ($ pmdRaw , true );
74+ $ cleanJson = substr ($ pmdRaw , $ jsonStart );
75+ $ pmdJson = json_decode ($ cleanJson , true );
76+
7377if (json_last_error () !== JSON_ERROR_NONE ) {
7478 http_response_code (500 );
75- echo json_encode (['error ' => 'PMD JSON parse error ' , 'raw ' => $ pmdRaw ]);
79+ echo json_encode ([
80+ 'error ' => 'JSON decode failed: ' . json_last_error_msg (),
81+ 'raw ' => $ pmdRaw ,
82+ 'clean ' => $ cleanJson
83+ ]);
7684 exit ;
7785}
7886
79- /* ---------- 9. Return only the violations ---------- */
87+ /* ---------- 9. Return violations ---------- */
8088$ violations = $ pmdJson ['files ' ][0 ]['violations ' ] ?? [];
81- echo json_encode (['violations ' => $ violations , 'debug ' => 'OK ' ]);
89+ echo json_encode ([
90+ 'violations ' => $ violations ,
91+ 'debug ' => 'PMD executed and parsed successfully '
92+ ]);
You can’t perform that action at this time.
0 commit comments