ForeachItemsAssignToEmptyArrayToAssignRector

Change foreach() items assign to empty array to direct assign

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

-        foreach ($items as $item) {
-             $collectedItems[] = $item;
-        }
+        $collectedItems = $items;
     }
 }

Configure your rector.php:

<?php

use Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withRules([
        ForeachItemsAssignToEmptyArrayToAssignRector::class,
    ]);
SETS:  Code Quality