TypeWillReturnCallableArrowFunctionRector

Decorate callbacks and arrow functions in willReturnCallback() with known param/return types based on reflection method

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function testSomething()
     {
         $this->createMock(SomeClass::class)
             ->method('someMethod')
-            ->willReturnCallback(function ($arg) {
-                return $arg;
-            });
+            ->willReturnCallback(
+                function (string $arg): string {
+                    return $arg;
+                }
+            );
     }
 }

 final class SomeClass
 {
     public function someMethod(string $arg): string
     {
         return $arg . ' !';
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\Class_\TypeWillReturnCallableArrowFunctionRector;

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