ChangeNestedForeachIfsToEarlyContinueRector

Change nested ifs to foreach with continue

 class SomeClass
 {
     public function run()
     {
         $items = [];

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

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;

return RectorConfig::configure()
    ->withRules([
        ChangeNestedForeachIfsToEarlyContinueRector::class,
    ]);
SETS:  Early return