Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ function & notAnonymous()
return $var;
}
}

function & notAnonymous2()
{
for ($i = 0; $i < 4; $i++) {
switch ($i) {
case 1:
$var = 42;
return $var;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Switch_;
use PhpParser\NodeVisitorAbstract;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -50,6 +51,14 @@ private function setByRefAttribute(array $stmts): void
continue;
}

if ($stmt instanceof Switch_) {
foreach ($stmt->cases as $case) {
$this->setByRefAttribute($case->stmts);
}

continue;
}

if ($stmt instanceof Return_) {
$stmt->setAttribute(AttributeKey::IS_BYREF_RETURN, true);
}
Expand Down
Loading