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 @@ -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)
Expand All @@ -227,10 +231,6 @@ private function isVariableSharedInAssignIfsAndReturn(
if ($isVariableUsed) {
return false;
}

if (! $this->nodeComparator->areNodesEqual($assign->var, $returnedExpr)) {
return false;
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions rules/Transform/Rector/ClassMethod/WrapReturnRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Loading