@@ -140,21 +140,28 @@ final class File extends AbstractNode
140
140
*/
141
141
private array $ codeUnitsByLine = [];
142
142
143
+ /**
144
+ * @var array<int, int>
145
+ */
146
+ private array $ executableLinesGroupedByBranch = [];
147
+
143
148
/**
144
149
* @param array<int, ?list<non-empty-string>> $lineCoverageData
145
150
* @param array<string, TestType> $testData
146
151
* @param array<string, Class_> $classes
147
152
* @param array<string, Trait_> $traits
148
153
* @param array<string, Function_> $functions
154
+ * @param array<int, int> $executableLinesGroupedByBranch
149
155
*/
150
- public function __construct (string $ name , AbstractNode $ parent , array $ lineCoverageData , array $ functionCoverageData , array $ testData , array $ classes , array $ traits , array $ functions , LinesOfCode $ linesOfCode )
156
+ public function __construct (string $ name , AbstractNode $ parent , array $ lineCoverageData , array $ functionCoverageData , array $ testData , array $ classes , array $ traits , array $ functions , LinesOfCode $ linesOfCode, array $ executableLinesGroupedByBranch )
151
157
{
152
158
parent ::__construct ($ name , $ parent );
153
159
154
- $ this ->lineCoverageData = $ lineCoverageData ;
160
+ $ this ->lineCoverageData = $ lineCoverageData ;
155
161
$ this ->functionCoverageData = $ functionCoverageData ;
156
- $ this ->testData = $ testData ;
157
- $ this ->linesOfCode = $ linesOfCode ;
162
+ $ this ->testData = $ testData ;
163
+ $ this ->linesOfCode = $ linesOfCode ;
164
+ $ this ->executableLinesGroupedByBranch = $ executableLinesGroupedByBranch ;
158
165
159
166
$ this ->calculateStatistics ($ classes , $ traits , $ functions );
160
167
}
@@ -374,8 +381,11 @@ private function calculateStatistics(array $classes, array $traits, array $funct
374
381
$ this ->processTraits ($ traits );
375
382
$ this ->processFunctions ($ functions );
376
383
384
+ // Get executable lines from the ExecutableLinesFindingVisitor
385
+ $ executableLines = $ this ->executableLinesGroupedByBranch ();
386
+
377
387
foreach (range (1 , $ this ->linesOfCode ->linesOfCode ()) as $ lineNumber ) {
378
- if (isset ($ this -> lineCoverageData [$ lineNumber ])) {
388
+ if (isset ($ executableLines [$ lineNumber ])) {
379
389
foreach ($ this ->codeUnitsByLine [$ lineNumber ] as &$ codeUnit ) {
380
390
if (isset ($ codeUnit ['executableLines ' ])) {
381
391
$ codeUnit ['executableLines ' ]++;
@@ -386,7 +396,7 @@ private function calculateStatistics(array $classes, array $traits, array $funct
386
396
387
397
$ this ->numExecutableLines ++;
388
398
389
- if (count ($ this ->lineCoverageData [$ lineNumber ]) > 0 ) {
399
+ if (isset ( $ this -> lineCoverageData [ $ lineNumber ]) && count ($ this ->lineCoverageData [$ lineNumber] ?? [ ]) > 0 ) {
390
400
foreach ($ this ->codeUnitsByLine [$ lineNumber ] as &$ codeUnit ) {
391
401
if (isset ($ codeUnit ['executedLines ' ])) {
392
402
$ codeUnit ['executedLines ' ]++;
@@ -699,4 +709,12 @@ static function (array $path)
699
709
700
710
return $ methodData ;
701
711
}
712
+
713
+ /**
714
+ * @return array<int, int>
715
+ */
716
+ private function executableLinesGroupedByBranch (): array
717
+ {
718
+ return $ this ->executableLinesGroupedByBranch ;
719
+ }
702
720
}
0 commit comments