diff --git a/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php b/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php index ecbf9e97911..00b385b0124 100644 --- a/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php +++ b/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php @@ -219,6 +219,10 @@ private function isVariableSharedInAssignIfsAndReturn( foreach ($bareSingleAssignIfs as $bareSingleAssignIf) { $assign = $bareSingleAssignIf->getAssign(); + if (! $this->nodeComparator->areNodesEqual($assign->var, $returnedExpr)) { + return false; + } + $isVariableUsed = (bool) $this->betterNodeFinder->findFirst( [$bareSingleAssignIf->getIfCondExpr(), $assign->expr], fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $returnedExpr) @@ -227,10 +231,6 @@ private function isVariableSharedInAssignIfsAndReturn( if ($isVariableUsed) { return false; } - - if (! $this->nodeComparator->areNodesEqual($assign->var, $returnedExpr)) { - return false; - } } return true; diff --git a/rules/EarlyReturn/Rector/StmtsAwareInterface/ReturnEarlyIfVariableRector.php b/rules/EarlyReturn/Rector/StmtsAwareInterface/ReturnEarlyIfVariableRector.php index 4492a24b580..ce52e6f2222 100644 --- a/rules/EarlyReturn/Rector/StmtsAwareInterface/ReturnEarlyIfVariableRector.php +++ b/rules/EarlyReturn/Rector/StmtsAwareInterface/ReturnEarlyIfVariableRector.php @@ -122,11 +122,6 @@ private function matchOnlyIfStmtReturnExpr(Stmt $onlyIfStmt, Variable $returnVar return null; } - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($onlyIfStmt); - if ($phpDocInfo->getVarTagValueNode() instanceof VarTagValueNode) { - return null; - } - $assign = $onlyIfStmt->expr; // assign to same variable that is returned @@ -146,6 +141,11 @@ private function matchOnlyIfStmtReturnExpr(Stmt $onlyIfStmt, Variable $returnVar return null; } + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($onlyIfStmt); + if ($phpDocInfo->getVarTagValueNode() instanceof VarTagValueNode) { + return null; + } + // return directly return $assign->expr; } diff --git a/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php b/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php index c87c591efc9..09a74fe131e 100644 --- a/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php +++ b/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php @@ -197,10 +197,6 @@ private function createExplicitMethodCall( } foreach ($this->arrayDimFetchToMethodCalls as $arrayDimFetchToMethodCall) { - if (! $this->isObjectType($arrayDimFetch->var, $arrayDimFetchToMethodCall->getObjectType())) { - continue; - } - $method = match ($magicPropertyHandler) { MagicPropertyHandler::GET => $arrayDimFetchToMethodCall->getMethod(), MagicPropertyHandler::SET => $arrayDimFetchToMethodCall->getSetMethod(), @@ -212,6 +208,10 @@ private function createExplicitMethodCall( continue; } + if (! $this->isObjectType($arrayDimFetch->var, $arrayDimFetchToMethodCall->getObjectType())) { + continue; + } + $args = [new Arg($arrayDimFetch->dim)]; if ($expr instanceof Expr) { diff --git a/rules/Transform/Rector/ClassMethod/WrapReturnRector.php b/rules/Transform/Rector/ClassMethod/WrapReturnRector.php index d43a2415f5d..7b2874662ae 100644 --- a/rules/Transform/Rector/ClassMethod/WrapReturnRector.php +++ b/rules/Transform/Rector/ClassMethod/WrapReturnRector.php @@ -73,10 +73,6 @@ public function refactor(Node $node): ?Node $hasChanged = false; foreach ($this->typeMethodWraps as $typeMethodWrap) { - if (! $this->isObjectType($node, $typeMethodWrap->getObjectType())) { - continue; - } - foreach ($node->getMethods() as $classMethod) { if (! $this->isName($classMethod, $typeMethodWrap->getMethod())) { continue; @@ -86,6 +82,10 @@ public function refactor(Node $node): ?Node continue; } + if (! $this->isObjectType($node, $typeMethodWrap->getObjectType())) { + continue; + } + if ($typeMethodWrap->isArrayWrap() && $this->wrap($classMethod)) { $hasChanged = true; }