*/ final class StaticTypeMapper implements TypeMapperInterface { /** * @readonly * @var \Rector\Php\PhpVersionProvider */ private $phpVersionProvider; public function __construct(PhpVersionProvider $phpVersionProvider) { $this->phpVersionProvider = $phpVersionProvider; } public function getNodeClass() : string { return StaticType::class; } /** * @param StaticType $type */ public function mapToPHPStanPhpDocTypeNode(Type $type) : TypeNode { return $type->toPhpDocNode(); } /** * @param SimpleStaticType|StaticType $type */ public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node { if ($type instanceof SelfStaticType) { return new Name(ObjectReference::SELF); } if ($typeKind !== TypeKind::RETURN) { return new Name(ObjectReference::SELF); } if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::STATIC_RETURN_TYPE)) { return new Name(ObjectReference::SELF); } return new Name(ObjectReference::STATIC); } }