Skip to content

Commit 53e636f

Browse files
committed
better fix
1 parent 08e321e commit 53e636f

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,24 @@ private function computeReturns(): void
137137
*/
138138
private function getLines(NodeAbstract $node, bool $fromReturns): array
139139
{
140-
// ugly fix for non-fully AST based processing
141-
// self::afterTraverse()/self::computeReturns() should be rewritten using self::leaveNode()
142-
if ($node instanceof Array_ && [] !== $node->items) {
143-
$parentNode = $node->getAttribute('parent');
144-
if ($parentNode instanceof Return_ ||
145-
$parentNode instanceof Expression ||
146-
$parentNode instanceof Assign ||
147-
$parentNode instanceof Array_
148-
) {
149-
return [];
150-
}
151-
}
152-
153-
if (!$fromReturns && (
154-
$node instanceof Return_ ||
140+
if ($node instanceof Return_ ||
155141
$node instanceof Expression ||
156142
$node instanceof Assign ||
157143
$node instanceof Array_
158-
)
159144
) {
160-
$this->returns[] = $node;
145+
if (!$fromReturns) {
146+
$this->returns[] = $node;
161147

162-
return [];
148+
return [];
149+
}
150+
151+
// ugly fix for non-fully AST based processing
152+
// self::afterTraverse()/self::computeReturns() should be rewritten using self::leaveNode()
153+
foreach (range($node->getStartLine(), $node->getEndLine()) as $index) {
154+
if (isset($this->executableLines[$index])) {
155+
return [];
156+
}
157+
}
163158
}
164159

165160
if ($node instanceof Return_) {

tests/tests/Data/RawCodeCoverageDataTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,11 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
483483
327,
484484
340,
485485
351,
486-
355,
487486
370,
488487
377,
489488
390,
490-
392,
491489
402,
492-
404,
493490
414,
494-
416,
495491
425,
496492
437,
497493
442,

0 commit comments

Comments
 (0)