@@ -192,7 +192,100 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
192192 }
193193 }
194194
195+ if ($ report ->numberOfFunctions () === 0 ) {
196+ $ packageElement ->setAttribute ('complexity ' , (string ) $ packageComplexity );
197+
198+ continue ;
199+ }
200+
201+ $ functionsComplexity = 0 ;
202+ $ functionsLinesValid = 0 ;
203+ $ functionsLinesCovered = 0 ;
204+ $ functionsBranchesValid = 0 ;
205+ $ functionsBranchesCovered = 0 ;
206+
207+ $ classElement = $ document ->createElement ('class ' );
208+ $ classElement ->setAttribute ('name ' , basename ($ item ->pathAsString ()));
209+ $ classElement ->setAttribute ('filename ' , str_replace ($ report ->pathAsString () . '/ ' , '' , $ item ->pathAsString ()));
210+
211+ $ methodsElement = $ document ->createElement ('methods ' );
212+
213+ $ classElement ->appendChild ($ methodsElement );
214+
215+ $ classLinesElement = $ document ->createElement ('lines ' );
216+
217+ $ classElement ->appendChild ($ classLinesElement );
218+
219+ $ functions = $ report ->functions ();
220+
221+ foreach ($ functions as $ functionName => $ function ) {
222+ if ($ function ['executableLines ' ] === 0 ) {
223+ continue ;
224+ }
225+
226+ $ complexity += $ function ['ccn ' ];
227+ $ packageComplexity += $ function ['ccn ' ];
228+ $ functionsComplexity += $ function ['ccn ' ];
229+
230+ $ linesValid = $ function ['executableLines ' ];
231+ $ linesCovered = $ function ['executedLines ' ];
232+ $ lineRate = $ linesValid === 0 ? 0 : ($ linesCovered / $ linesValid );
233+
234+ $ functionsLinesValid += $ linesValid ;
235+ $ functionsLinesCovered += $ linesCovered ;
236+
237+ $ branchesValid = $ function ['executableBranches ' ];
238+ $ branchesCovered = $ function ['executedBranches ' ];
239+ $ branchRate = $ branchesValid === 0 ? 0 : ($ branchesCovered / $ branchesValid );
240+
241+ $ functionsBranchesValid += $ branchesValid ;
242+ $ functionsBranchesCovered += $ branchesValid ;
243+
244+ $ methodElement = $ document ->createElement ('method ' );
245+
246+ $ methodElement ->setAttribute ('name ' , $ functionName );
247+ $ methodElement ->setAttribute ('signature ' , $ function ['signature ' ]);
248+ $ methodElement ->setAttribute ('line-rate ' , (string ) $ lineRate );
249+ $ methodElement ->setAttribute ('branch-rate ' , (string ) $ branchRate );
250+ $ methodElement ->setAttribute ('complexity ' , (string ) $ function ['ccn ' ]);
251+
252+ $ methodLinesElement = $ document ->createElement ('lines ' );
253+
254+ $ methodElement ->appendChild ($ methodLinesElement );
255+
256+ foreach (range ($ function ['startLine ' ], $ function ['endLine ' ]) as $ line ) {
257+ if (!isset ($ coverageData [$ line ]) || $ coverageData [$ line ] === null ) {
258+ continue ;
259+ }
260+ $ methodLineElement = $ document ->createElement ('line ' );
261+
262+ $ methodLineElement ->setAttribute ('number ' , (string ) $ line );
263+ $ methodLineElement ->setAttribute ('hits ' , (string ) count ($ coverageData [$ line ]));
264+
265+ $ methodLinesElement ->appendChild ($ methodLineElement );
266+
267+ $ classLineElement = $ methodLineElement ->cloneNode ();
268+
269+ $ classLinesElement ->appendChild ($ classLineElement );
270+ }
271+
272+ $ methodsElement ->appendChild ($ methodElement );
273+ }
274+
195275 $ packageElement ->setAttribute ('complexity ' , (string ) $ packageComplexity );
276+
277+ if ($ functionsLinesValid === 0 ) {
278+ continue ;
279+ }
280+
281+ $ lineRate = $ functionsLinesCovered / $ functionsLinesValid ;
282+ $ branchRate = $ functionsBranchesValid === 0 ? 0 : ($ functionsBranchesCovered / $ functionsBranchesValid );
283+
284+ $ classElement ->setAttribute ('line-rate ' , (string ) $ lineRate );
285+ $ classElement ->setAttribute ('branch-rate ' , (string ) $ branchRate );
286+ $ classElement ->setAttribute ('complexity ' , (string ) $ functionsComplexity );
287+
288+ $ classesElement ->appendChild ($ classElement );
196289 }
197290
198291 $ coverageElement ->setAttribute ('complexity ' , (string ) $ complexity );
0 commit comments