Skip to content

Commit de335b8

Browse files
committed
Updated Rector to commit d025cdd0be230dcdad1510dbc73ce989623e868e
rectorphp/rector-src@d025cdd [EarlyReturn] Skip re-assign in loop on PreparedValueToEarlyReturnRector (#6867)
1 parent 28621a1 commit de335b8

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
use PhpParser\Node\Expr\AssignOp;
1010
use PhpParser\Node\Expr\Variable;
1111
use PhpParser\Node\Stmt;
12+
use PhpParser\Node\Stmt\Do_;
1213
use PhpParser\Node\Stmt\Expression;
14+
use PhpParser\Node\Stmt\For_;
15+
use PhpParser\Node\Stmt\Foreach_;
1316
use PhpParser\Node\Stmt\If_;
1417
use PhpParser\Node\Stmt\Return_;
18+
use PhpParser\Node\Stmt\While_;
1519
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1620
use Rector\EarlyReturn\ValueObject\BareSingleAssignIf;
1721
use Rector\NodeManipulator\IfManipulator;
@@ -100,6 +104,12 @@ public function refactor(Node $node) : ?StmtsAwareInterface
100104
if ($stmt instanceof Expression && $stmt->expr instanceof AssignOp) {
101105
return null;
102106
}
107+
if ($stmt instanceof For_ || $stmt instanceof Foreach_ || $stmt instanceof While_ || $stmt instanceof Do_) {
108+
$isReassignInLoop = (bool) $this->betterNodeFinder->findFirst($stmt, fn(Node $node): bool => $node instanceof Assign && $this->nodeComparator->areNodesEqual($node->var, ($nullsafeVariable1 = $initialAssign) ? $nullsafeVariable1->var : null));
109+
if ($isReassignInLoop) {
110+
return null;
111+
}
112+
}
103113
if ($stmt instanceof If_) {
104114
$ifs[$key] = $stmt;
105115
continue;

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'e5256b9b6aaf8a50383273dd955b4b40d4232053';
22+
public const PACKAGE_VERSION = 'd025cdd0be230dcdad1510dbc73ce989623e868e';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-04-26 07:00:52';
27+
public const RELEASE_DATE = '2025-04-26 21:24:46';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)