@@ -360,16 +360,18 @@ public function append(array $data, $id = null, bool $append = true, $linesToBeC
360
360
}
361
361
}
362
362
363
- foreach ($ fileData ['functions ' ] as $ function => $ functionCoverage ) {
364
- foreach ($ functionCoverage ['branches ' ] as $ branch => $ branchCoverage ) {
365
- if (($ branchCoverage ['hit ' ] ?? 0 ) === 1 ) {
366
- $ this ->addCoverageBranchHit ($ file , $ function , $ branch , $ branchCoverage ['hit ' ] ?? 0 );
367
- $ this ->addCoverageBranchTest ($ file , $ function , $ branch , $ id );
363
+ if ($ this ->determineBranchCoverage ) {
364
+ foreach ($ fileData ['functions ' ] as $ function => $ functionCoverage ) {
365
+ foreach ($ functionCoverage ['branches ' ] as $ branch => $ branchCoverage ) {
366
+ if (($ branchCoverage ['hit ' ] ?? 0 ) === 1 ) {
367
+ $ this ->addCoverageBranchHit ($ file , $ function , $ branch , $ branchCoverage ['hit ' ] ?? 0 );
368
+ $ this ->addCoverageBranchTest ($ file , $ function , $ branch , $ id );
369
+ }
368
370
}
369
- }
370
371
371
- foreach ($ functionCoverage ['paths ' ] as $ path => $ pathCoverage ) {
372
- $ this ->addCoveragePathHit ($ file , $ function , $ path , $ pathCoverage ['hit ' ] ?? 0 );
372
+ foreach ($ functionCoverage ['paths ' ] as $ path => $ pathCoverage ) {
373
+ $ this ->addCoveragePathHit ($ file , $ function , $ path , $ pathCoverage ['hit ' ] ?? 0 );
374
+ }
373
375
}
374
376
}
375
377
}
@@ -622,20 +624,21 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data): void
622
624
} else {
623
625
$ this ->addCoverageLinePathCovered ($ file , $ lineNumber , false );
624
626
}
625
-
626
627
}
627
628
628
- foreach ($ fileData ['functions ' ] as $ functionName => $ functionData ) {
629
- $ this ->data [$ file ]['paths ' ][$ functionName ] = $ functionData ['paths ' ];
629
+ if ($ this ->determineBranchCoverage ) {
630
+ foreach ($ fileData ['functions ' ] as $ functionName => $ functionData ) {
631
+ $ this ->data [$ file ]['paths ' ][$ functionName ] = $ functionData ['paths ' ];
630
632
631
- foreach ($ functionData ['branches ' ] as $ branchIndex => $ branchData ) {
632
- $ this ->addCoverageBranchHit ($ file , $ functionName , $ branchIndex , $ branchData ['hit ' ]);
633
- $ this ->addCoverageBranchLineStart ($ file , $ functionName , $ branchIndex , $ branchData ['line_start ' ]);
634
- $ this ->addCoverageBranchLineEnd ($ file , $ functionName , $ branchIndex , $ branchData ['line_end ' ]);
633
+ foreach ($ functionData ['branches ' ] as $ branchIndex => $ branchData ) {
634
+ $ this ->addCoverageBranchHit ($ file , $ functionName , $ branchIndex , $ branchData ['hit ' ]);
635
+ $ this ->addCoverageBranchLineStart ($ file , $ functionName , $ branchIndex , $ branchData ['line_start ' ]);
636
+ $ this ->addCoverageBranchLineEnd ($ file , $ functionName , $ branchIndex , $ branchData ['line_end ' ]);
635
637
636
- for ($ curLine = $ branchData ['line_start ' ]; $ curLine < $ branchData ['line_end ' ]; $ curLine ++) {
637
- if (isset ($ this ->data [$ file ]['lines ' ][$ curLine ])) {
638
- $ this ->addCoverageLinePathCovered ($ file , $ curLine , (bool ) $ branchData ['hit ' ]);
638
+ for ($ curLine = $ branchData ['line_start ' ]; $ curLine < $ branchData ['line_end ' ]; $ curLine ++) {
639
+ if (isset ($ this ->data [$ file ]['lines ' ][$ curLine ])) {
640
+ $ this ->addCoverageLinePathCovered ($ file , $ curLine , (bool ) $ branchData ['hit ' ]);
641
+ }
639
642
}
640
643
}
641
644
}
@@ -646,11 +649,17 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data): void
646
649
private function initializeFileCoverageData (string $ file ): void
647
650
{
648
651
if (!isset ($ this ->data [$ file ]) && $ this ->filter ->isFile ($ file )) {
649
- $ this ->data [$ file ] = [
650
- 'lines ' => [],
651
- 'branches ' => [],
652
- 'paths ' => [],
653
- ];
652
+ $ default = ['lines ' => []];
653
+
654
+ if ($ this ->determineBranchCoverage ) {
655
+ $ default = [
656
+ 'lines ' => [],
657
+ 'branches ' => [],
658
+ 'paths ' => [],
659
+ ];
660
+ }
661
+
662
+ $ this ->data [$ file ] = $ default ;
654
663
}
655
664
}
656
665
@@ -689,6 +698,9 @@ private function addCoverageLineTest(string $file, int $lineNumber, string $test
689
698
private function addCoverageBranchHit (string $ file , string $ functionName , int $ branchIndex , int $ hit ): void
690
699
{
691
700
$ this ->initializeFileCoverageData ($ file );
701
+ if (!$ this ->determineBranchCoverage ) {
702
+ return ;
703
+ }
692
704
693
705
if (!\array_key_exists ($ functionName , $ this ->data [$ file ]['branches ' ])) {
694
706
$ this ->data [$ file ]['branches ' ][$ functionName ] = [];
@@ -717,6 +729,10 @@ private function addCoverageBranchLineStart(
717
729
): void {
718
730
$ this ->initializeFileCoverageData ($ file );
719
731
732
+ if (!$ this ->determineBranchCoverage ) {
733
+ return ;
734
+ }
735
+
720
736
if (!\array_key_exists ($ functionName , $ this ->data [$ file ]['branches ' ])) {
721
737
$ this ->data [$ file ]['branches ' ][$ functionName ] = [];
722
738
}
@@ -741,6 +757,10 @@ private function addCoverageBranchLineEnd(
741
757
): void {
742
758
$ this ->initializeFileCoverageData ($ file );
743
759
760
+ if (!$ this ->determineBranchCoverage ) {
761
+ return ;
762
+ }
763
+
744
764
if (!\array_key_exists ($ functionName , $ this ->data [$ file ]['branches ' ])) {
745
765
$ this ->data [$ file ]['branches ' ][$ functionName ] = [];
746
766
}
@@ -765,6 +785,10 @@ private function addCoverageBranchTest(
765
785
): void {
766
786
$ this ->initializeFileCoverageData ($ file );
767
787
788
+ if (!$ this ->determineBranchCoverage ) {
789
+ return ;
790
+ }
791
+
768
792
if (!\array_key_exists ($ functionName , $ this ->data [$ file ]['branches ' ])) {
769
793
$ this ->data [$ file ]['branches ' ][$ functionName ] = [];
770
794
}
@@ -791,6 +815,10 @@ private function addCoveragePathHit(
791
815
): void {
792
816
$ this ->initializeFileCoverageData ($ file );
793
817
818
+ if (!$ this ->determineBranchCoverage ) {
819
+ return ;
820
+ }
821
+
794
822
if (!\array_key_exists ($ functionName , $ this ->data [$ file ]['paths ' ])) {
795
823
$ this ->data [$ file ]['paths ' ][$ functionName ] = [];
796
824
}
0 commit comments