Add string return type based on returned string scalar values
final class SomeClass
{
- public function foo($condition)
+ public function foo($condition): string
{
if ($condition) {
return 'yes';
}
return 'no';
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\StringReturnTypeFromStrictScalarReturnsRector;
return RectorConfig::configure()
->withRules([
StringReturnTypeFromStrictScalarReturnsRector::class,
]);