Add known type declarations based on first-level try/catch return values
final class SomeClass
{
- public function run()
+ public function run(): int
{
try {
return 1;
} catch (\Exception $e) {
return 2;
}
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeFromTryCatchTypeRector;
return RectorConfig::configure()
->withRules([
AddReturnTypeFromTryCatchTypeRector::class,
]);