Skip to content

[EarlyReturn] Deprecate ChangeNestedForeachIfsToEarlyContinueRector - #8303

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-nested-foreach-ifs-early-continue
Aug 5, 2026
Merged

[EarlyReturn] Deprecate ChangeNestedForeachIfsToEarlyContinueRector#8303
TomasVotruba merged 1 commit into
mainfrom
deprecate-nested-foreach-ifs-early-continue

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Deprecates ChangeNestedForeachIfsToEarlyContinueRector.

Inverting nested ifs into continue guards makes the code harder to read and understand. Whether the early-continue shape is better depends on the surrounding context, which the rule cannot know.

 foreach ($values as $value) {
-    if ($value === 5) {
-        if ($value2 === 10) {
-            $items[] = 'maybe';
-        }
-    }
+    if ($value !== 5) {
+        continue;
+    }
+    if ($value2 !== 10) {
+        continue;
+    }
+
+    $items[] = 'maybe';
 }

The rule now implements DeprecatedInterface and throws on use. It is removed from the early-return set, and its tests are dropped.

Also removes IfManipulator::collectNestedIfsWithNonBreaking(), its only caller.

@TomasVotruba
TomasVotruba merged commit 5811529 into main Aug 5, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-nested-foreach-ifs-early-continue branch August 5, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant