Skip to content

Commit 63923bc

Browse files
committed
Rector 2.0.14
1 parent 9afd587 commit 63923bc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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_) && $initialAssign instanceof Assign) {
108+
$isReassignInLoop = (bool) $this->betterNodeFinder->findFirst($stmt, fn(Node $node): bool => $node instanceof Assign && $this->nodeComparator->areNodesEqual($node->var, $initialAssign->var));
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 = '2.0.13';
22+
public const PACKAGE_VERSION = '2.0.14';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-04-24 15:52:43';
27+
public const RELEASE_DATE = '2025-04-26 18:10:08';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)