Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeQuality] Skip used in next stmt on UnusedForeachValueToArrayKeysRector #6164

Merged
merged 3 commits into from
Jul 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
clean up
  • Loading branch information
samsonasik committed Jul 20, 2024
commit b429662a9adb5a63f1cfc55a216fe14125a5b9bc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function refactor(Node $node): ?Node
continue;
}

if (! $this->isArrayType($stmt->expr)) {
continue;
}

// special case of nested array items
if ($stmt->valueVar instanceof Array_) {
$valueArray = $this->refactorArrayForeachValue($stmt->valueVar, $stmt);
Expand All @@ -113,23 +117,19 @@ public function refactor(Node $node): ?Node
continue;
}

if ($stmt->valueVar instanceof Variable) {
if ($this->isVariableUsedInForeach($stmt->valueVar, $stmt)) {
continue;
}
if (! $stmt->valueVar instanceof Variable) {
continue;
}

if ($this->stmtsManipulator->isVariableUsedInNextStmt(
$stmts,
$key + 1,
(string) $this->getName($stmt->valueVar)
)) {
continue;
}
} else {
if ($this->isVariableUsedInForeach($stmt->valueVar, $stmt)) {
continue;
}

if (! $this->isArrayType($stmt->expr)) {
if ($this->stmtsManipulator->isVariableUsedInNextStmt(
$stmts,
$key + 1,
(string) $this->getName($stmt->valueVar)
)) {
continue;
}

Expand Down