rector/rules/TypeDeclaration/FunctionLikeReturnTypeResolver.php
Tomas Votruba 23a994ee6e Updated Rector to commit 183bb5bda001a9d8d7302a350fe4c8979dbe4f19
183bb5bda0 Remove ReturnTypeDeclarationReturnTypeInferer (#3117)
2022-11-28 12:02:35 +00:00

30 lines
849 B
PHP

<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\StaticTypeMapper\StaticTypeMapper;
final class FunctionLikeReturnTypeResolver
{
/**
* @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/
private $staticTypeMapper;
public function __construct(StaticTypeMapper $staticTypeMapper)
{
$this->staticTypeMapper = $staticTypeMapper;
}
public function resolveFunctionLikeReturnTypeToPHPStanType(ClassMethod $classMethod) : Type
{
$functionReturnType = $classMethod->getReturnType();
if ($functionReturnType === null) {
return new MixedType();
}
return $this->staticTypeMapper->mapPhpParserNodePHPStanType($functionReturnType);
}
}