Skip to content

Commit a11c1e5

Browse files
committed
Fix return with multiline variable in array and with expr not be coverage
1 parent 2fde509 commit a11c1e5

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ private function getLines(Node $node): array
137137
{
138138
if ($node instanceof BinaryOp) {
139139
if (($node->left instanceof Node\Scalar ||
140-
$node->left instanceof Node\Expr\ConstFetch) &&
140+
$node->left instanceof Node\Expr\ConstFetch ||
141+
$node->left instanceof Node\Expr\Variable) &&
141142
($node->right instanceof Node\Scalar ||
142-
$node->right instanceof Node\Expr\ConstFetch)) {
143+
$node->right instanceof Node\Expr\ConstFetch
144+
|| $node->right instanceof Node\Expr\Variable)) {
143145
return [$node->right->getStartLine()];
144146
}
145147

tests/_files/source_with_multiline_constant_return.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,17 @@ public function Spaceship(): int
244244
1
245245
;
246246
}
247+
248+
public function VariableInArray(): int
249+
{
250+
$n = 1;
251+
252+
return
253+
[
254+
2 + $n,
255+
$n ,
256+
2 . $n,
257+
]
258+
;
259+
}
247260
}

tests/tests/Data/RawCodeCoverageDataTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
417417
226,
418418
235,
419419
244,
420+
250,
421+
254,
422+
256,
420423
],
421424
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
422425
);

0 commit comments

Comments
 (0)