ReturnTypeFromReturnCastRector

Add return type to function like with return cast

 final class SomeClass
 {
-    public function action($param)
+    public function action($param): array
     {
         try {
             return (array) $param;
         } catch (Exception $exception) {
             // some logging
             throw $exception;
         }
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnCastRector;

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