Configurable

AddClosureParamTypeFromObjectRector

Add closure param type based on the object of the method call

 $request = new Request();
-$request->when(true, function ($request) {});
+$request->when(true, function (Request $request) {});

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\FunctionLike\AddClosureParamTypeFromObjectRector;
use Rector\TypeDeclaration\ValueObject\AddClosureParamTypeFromObject;

return RectorConfig::configure()
    ->withConfiguredRule(AddClosureParamTypeFromObjectRector::class, [
        new AddClosureParamTypeFromObject('Request', 'when', 1, 0),
    ]);