Change object param type based on passed method call type
class SomeTypedService
{
public function run(SomeObject $object)
{
}
}
final class UseDependency
{
public function __construct(
private SomeTypedService $someTypedService
) {
}
- public function go($value)
+ public function go(SomeObject $value)
{
$this->someTypedService->run($value);
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector;
return RectorConfig::configure()
->withRules([
ObjectParamTypeByMethodCallTypeRector::class,
]);