Skip to content

Commit

Permalink
[EarlyReturn] Skip indirect return with define variable after parent …
Browse files Browse the repository at this point in the history
…else on ChangeAndIfToEarlyReturnRector (#2836)

* Add failing test fixture for ChangeAndIfToEarlyReturnRector

# Failing Test for ChangeAndIfToEarlyReturnRector

Based on https://getrector.org/demo/5cf285f8-b9ba-40f6-bd8c-7c325bb2458d

* update fixture

* update

* Closes #2823 Fixes rectorphp/rector#7413

* [ci-review] Rector Rectify

Co-authored-by: Shin <2082119+shinsenter@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
3 people committed Aug 24, 2022
1 parent 84691d5 commit c8e66ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

function dummy_wrap($maxWidth, $text)
{
if (get_font_set()) {
} else {
$nb = strlen($s);

if ($nb > 0 && $s[$nb - 1] == "\n") {
$nb--;
}
}

$nl = 1;

return $nl;
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ private function shouldSkip(StmtsAwareInterface $stmtsAware, If_ $if, ?Stmt $nex
private function isParentIfReturnsVoidOrParentIfHasNextNode(StmtsAwareInterface $stmtsAware): bool
{
if (! $stmtsAware instanceof If_) {
$parent = $stmtsAware->getAttribute(AttributeKey::PARENT_NODE);
if ($parent instanceof If_) {
$node = $parent->getAttribute(AttributeKey::NEXT_NODE);
return ! $node instanceof Return_;
}

return false;
}

Expand Down

0 comments on commit c8e66ae

Please sign in to comment.