AddClosureParamTypeFromIterableMethodCallRector

Applies type hints to closures on Iterable method calls where key/value types are documented

 class SomeClass
 {
     /**
      * @param Collection<int, string> $collection
      */
     public function run(Collection $collection)
     {
-        return $collection->map(function ($item, $key) {
+        return $collection->map(function (string $item, int $key) {
             return $item . $key;
         });
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\FunctionLike\AddClosureParamTypeFromIterableMethodCallRector;

return RectorConfig::configure()
    ->withRules([
        AddClosureParamTypeFromIterableMethodCallRector::class,
    ]);