mirror of https://github.com/rectorphp/rector.git
30 lines
849 B
PHP
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);
|
|
}
|
|
}
|