@@ -346,15 +346,36 @@ public function append(array $data, $id = null, bool $append = true, $linesToBeC
346
346
347
347
$ this ->tests [$ id ] = ['size ' => $ size , 'status ' => $ status ];
348
348
349
- foreach ($ data as $ file => $ lines ) {
349
+ foreach ($ data as $ file => $ fileData ) {
350
350
if (!$ this ->filter ->isFile ($ file )) {
351
351
continue ;
352
352
}
353
353
354
- foreach ($ lines as $ k => $ v ) {
355
- if ($ v === Driver::LINE_EXECUTED ) {
356
- if (empty ($ this ->data [$ file ][$ k ]) || !\in_array ($ id , $ this ->data [$ file ][$ k ])) {
357
- $ this ->data [$ file ][$ k ][] = $ id ;
354
+ foreach ($ fileData ['lines ' ] as $ line => $ lineCoverage ) {
355
+ if ($ lineCoverage === Driver::LINE_EXECUTED ) {
356
+ if ($ this ->data [$ file ]['lines ' ][$ line ] === null ) {
357
+ $ this ->data [$ file ]['lines ' ][$ line ] = [
358
+ 'pathCovered ' => false ,
359
+ 'tests ' => [$ id ],
360
+ ];
361
+ } elseif (!\in_array ($ id , $ this ->data [$ file ]['lines ' ][$ line ]['tests ' ], true )) {
362
+ $ this ->data [$ file ]['lines ' ][$ line ]['tests ' ][] = [$ id ];
363
+ }
364
+ }
365
+ }
366
+
367
+ foreach ($ fileData ['functions ' ] as $ function => $ functionCoverage ) {
368
+ foreach ($ functionCoverage ['branches ' ] as $ branch => $ branchCoverage ) {
369
+ if ($ branchCoverage ['hit ' ] === 1 ) {
370
+ $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['hit ' ] = 1 ;
371
+ if (!\in_array ($ id , $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['tests ' ], true )) {
372
+ $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['tests ' ][] = $ id ;
373
+ }
374
+ }
375
+ }
376
+ foreach ($ functionCoverage ['paths ' ] as $ path => $ pathCoverage ) {
377
+ if ($ pathCoverage ['hit ' ] === 1 && $ this ->data [$ file ]['paths ' ][$ function ][$ path ]['hit ' ] === 0 ) {
378
+ $ this ->data [$ file ]['paths ' ][$ function ][$ path ]['hit ' ] = 1 ;
358
379
}
359
380
}
360
381
}
@@ -374,10 +395,11 @@ public function merge(self $that): void
374
395
\array_merge ($ this ->filter ->getWhitelistedFiles (), $ that ->filter ()->getWhitelistedFiles ())
375
396
);
376
397
377
- foreach ($ that ->data as $ file => $ lines ) {
398
+ // I don't know how / why this works, but it should be refactored to ->getData()
399
+ foreach ($ that ->getData () as $ file => $ fileData ) {
378
400
if (!isset ($ this ->data [$ file ])) {
379
401
if (!$ this ->filter ->isFiltered ($ file )) {
380
- $ this ->data [$ file ] = $ lines ;
402
+ $ this ->data [$ file ] = $ fileData ;
381
403
}
382
404
383
405
continue ;
@@ -386,20 +408,23 @@ public function merge(self $that): void
386
408
// we should compare the lines if any of two contains data
387
409
$ compareLineNumbers = \array_unique (
388
410
\array_merge (
389
- \array_keys ($ this ->data [$ file ]),
390
- \array_keys ($ that ->data [$ file ])
411
+ \array_keys ($ this ->data [$ file ][ ' lines ' ] ),
412
+ \array_keys ($ that ->data [$ file ][ ' lines ' ]) // can this be $fileData?
391
413
)
392
414
);
393
415
394
416
foreach ($ compareLineNumbers as $ line ) {
395
- $ thatPriority = $ this ->getLinePriority ($ that ->data [$ file ], $ line );
396
- $ thisPriority = $ this ->getLinePriority ($ this ->data [$ file ], $ line );
417
+ $ thatPriority = $ this ->getLinePriority ($ that ->data [$ file ][ ' lines ' ] , $ line );
418
+ $ thisPriority = $ this ->getLinePriority ($ this ->data [$ file ][ ' lines ' ] , $ line );
397
419
398
420
if ($ thatPriority > $ thisPriority ) {
399
- $ this ->data [$ file ][$ line ] = $ that ->data [$ file ][$ line ];
400
- } elseif ($ thatPriority === $ thisPriority && \is_array ($ this ->data [$ file ][$ line ])) {
401
- $ this ->data [$ file ][$ line ] = \array_unique (
402
- \array_merge ($ this ->data [$ file ][$ line ], $ that ->data [$ file ][$ line ])
421
+ $ this ->data [$ file ]['lines ' ][$ line ] = $ that ->data [$ file ]['lines ' ][$ line ];
422
+ } elseif ($ thatPriority === $ thisPriority && \is_array ($ this ->data [$ file ]['lines ' ][$ line ])) {
423
+ if ($ line ['pathCovered ' ] === true ) {
424
+ $ this ->data [$ file ]['lines ' ]['line ' ]['pathCovered ' ] = $ line ['pathCovered ' ];
425
+ }
426
+ $ this ->data [$ file ]['lines ' ][$ line ] = \array_unique (
427
+ \array_merge ($ this ->data [$ file ]['lines ' ][$ line ], $ that ->data [$ file ]['lines ' ][$ line ])
403
428
);
404
429
}
405
430
}
0 commit comments