NarrowObjectReturnTypeRector

Narrows return type from generic object or parent class to specific class in final classes/methods

 final class TalkFactory extends AbstractFactory
 {
-    protected function build(): object
+    protected function build(): ConferenceTalk
     {
         return new ConferenceTalk();
     }
 }

Configure your rector.php:

<?php

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

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