Skip to content
Merged
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
20 changes: 10 additions & 10 deletions packages/CodeQuality/src/Rector/Foreach_/ForeachToInArrayRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ public function refactor(Node $node): ?Node
$ifCondition = $firstNodeInsideForeach->cond;
$foreachValueVar = $node->valueVar;

$foreachValueStaticType = $this->getStaticType($node->expr);
if ($foreachValueStaticType instanceof ObjectType) {
return null;
}

$matchedNodes = $this->matchNodes($ifCondition, $foreachValueVar);
if ($matchedNodes === null) {
return null;
Expand Down Expand Up @@ -145,17 +140,17 @@ public function refactor(Node $node): ?Node
return $return;
}

private function shouldSkipForeach(Foreach_ $foreachNode): bool
private function shouldSkipForeach(Foreach_ $foreach): bool
{
if (isset($foreachNode->keyVar)) {
if (isset($foreach->keyVar)) {
return true;
}

if (count($foreachNode->stmts) > 1) {
if (count($foreach->stmts) > 1) {
return true;
}

$nextNode = $foreachNode->getAttribute(AttributeKey::NEXT_NODE);
$nextNode = $foreach->getAttribute(AttributeKey::NEXT_NODE);
if ($nextNode === null || ! $nextNode instanceof Return_) {
return true;
}
Expand All @@ -170,7 +165,12 @@ private function shouldSkipForeach(Foreach_ $foreachNode): bool
return true;
}

return ! $foreachNode->stmts[0] instanceof If_;
$foreachValueStaticType = $this->getStaticType($foreach->expr);
if ($foreachValueStaticType instanceof ObjectType) {
return true;
}

return ! $foreach->stmts[0] instanceof If_;
}

private function shouldSkipIf(If_ $ifNode): bool
Expand Down