Skip to content

Commit d457c77

Browse files
Slamdunkmvorisek
authored andcommitted
Fix Concat operations with variables sebastianbergmann#953
1 parent 8dfe7b2 commit d457c77

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

+8
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ private function getLines(NodeAbstract $node, bool $fromReturns): array
165165
}
166166

167167
if ($node instanceof BinaryOp) {
168+
if ($node instanceof BinaryOp\Concat &&
169+
(
170+
$node->left instanceof Node\Expr\Variable ||
171+
$node->right instanceof Node\Expr\Variable
172+
)) {
173+
return [$node->right->getStartLine()];
174+
}
175+
168176
return $fromReturns ? $this->getLines($node->right, $fromReturns) : [];
169177
}
170178

tests/_files/source_with_multiline_constant_return.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function unaryLogicalNotWithNotConstInTheMiddle(): bool
396396
public function unaryMinusWithNotConstInTheMiddle(): float
397397
{
398398
return -
399-
(
399+
(int) (
400400
''
401401
.
402402
phpversion()
@@ -485,10 +485,30 @@ public function unaryMinusNowdoc(): float
485485
{
486486
return
487487
-
488+
(int)
488489
<<<'EOF'
489490
1.
490491
2
491492
EOF
492493
;
493494
}
495+
496+
public function concatWithVar(): string
497+
{
498+
$var1 = 'start';
499+
500+
$var1 =
501+
'right'
502+
.
503+
$var1
504+
;
505+
506+
$var1 =
507+
$var1
508+
.
509+
'left'
510+
;
511+
512+
return $var1;
513+
}
494514
}

tests/tests/Data/RawCodeCoverageDataTest.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,13 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
497497
456,
498498
466,
499499
478,
500-
489,
500+
490,
501+
498,
502+
500,
503+
503,
504+
506,
505+
509, // This is correct: not the line with the $var1, but the right operand of the Concat
506+
512,
501507
],
502508
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
503509
);

0 commit comments

Comments
 (0)