Skip to content

Fix concat with var, again #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/StaticAnalysis/ExecutableLinesFindingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ private function getLines(NodeAbstract $node, bool $fromReturns): array
}

if ($node instanceof BinaryOp) {
if ($node instanceof BinaryOp\Concat &&
(
$node->left instanceof Node\Expr\Variable ||
$node->right instanceof Node\Expr\Variable
)) {
return [$this->getNodeStartLine($node->right)];
}

return $fromReturns ? $this->getLines($node->right, $fromReturns) : [];
}

Expand Down
23 changes: 23 additions & 0 deletions tests/_files/source_with_multiline_constant_return.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,27 @@ public function nestedArrayWithExecutableInKey(): array
]
];
}

public function concatWithVar(): string
{
$var1 = 'start';

$var1 =
<<<'EOF'
right
EOF
.
$var1
;

$var1 =
$var1
.
<<<'EOF'
left
EOF
;

return $var1;
}
}
6 changes: 6 additions & 0 deletions tests/tests/Data/RawCodeCoverageDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
537,
549,
562,
571,
573,
578,
581,
585,
589,
],
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
);
Expand Down