Type Resolver

TypeResolver
in package

FinalYes

Table of Contents

Constants

OPERATOR_NAMESPACE  = '\\'

Properties

$fqsenResolver  : FqsenResolver
$keywords  : array<string, string>
$lexer  : Lexer
$typeParser  : TypeParser

Methods

__construct()  : mixed
Initializes this TypeResolver with the means to create and resolve Fqsen objects.
addKeyword()  : void
Adds a keyword to the list of Keywords and associates it with a specific Value Object.
createType()  : Type
resolve()  : Type
Analyzes the given type and returns the FQCN variant.
createFromCallable()  : Callable_
createFromConst()  : Type
createFromGeneric()  : Type
createTypesByTypeNodes()  : array<string|int, Type>
isFqsen()  : bool
Tests whether the given type is a Fully Qualified Structural Element Name.
isKeyword()  : bool
Detects whether the given type represents a PHPDoc keyword.
isPartialStructuralElementName()  : bool
Detects whether the given type represents a relative structural element name.
parse()  : TypeNode
resolveKeyword()  : Type
Resolves the given keyword (such as `string`) into a Type object representing that keyword.
resolveSingleType()  : Type|Array_|Object_
resolve the given type into a type object
resolveTypedObject()  : Object_
Resolves the given FQSEN string into an FQSEN object.

Constants

OPERATOR_NAMESPACE

private string OPERATOR_NAMESPACE = '\\'

Definition of the NAMESPACE operator in PHP

Properties

$keywords

private array<string, string> $keywords = ['string' => \phpDocumentor\Reflection\Types\String_::class, 'class-string' => \phpDocumentor\Reflection\PseudoTypes\ClassString::class, 'interface-string' => \phpDocumentor\Reflection\PseudoTypes\InterfaceString::class, 'html-escaped-string' => \phpDocumentor\Reflection\PseudoTypes\HtmlEscapedString::class, 'lowercase-string' => \phpDocumentor\Reflection\PseudoTypes\LowercaseString::class, 'non-empty-lowercase-string' => \phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString::class, 'non-empty-string' => \phpDocumentor\Reflection\PseudoTypes\NonEmptyString::class, 'numeric-string' => \phpDocumentor\Reflection\PseudoTypes\NumericString::class, 'numeric' => \phpDocumentor\Reflection\PseudoTypes\Numeric_::class, 'trait-string' => \phpDocumentor\Reflection\PseudoTypes\TraitString::class, 'enum-string' => \phpDocumentor\Reflection\PseudoTypes\EnumString::class, 'int' => \phpDocumentor\Reflection\Types\Integer::class, 'integer' => \phpDocumentor\Reflection\Types\Integer::class, 'positive-int' => \phpDocumentor\Reflection\PseudoTypes\PositiveInteger::class, 'negative-int' => \phpDocumentor\Reflection\PseudoTypes\NegativeInteger::class, 'bool' => \phpDocumentor\Reflection\Types\Boolean::class, 'boolean' => \phpDocumentor\Reflection\Types\Boolean::class, 'real' => \phpDocumentor\Reflection\Types\Float_::class, 'float' => \phpDocumentor\Reflection\Types\Float_::class, 'double' => \phpDocumentor\Reflection\Types\Float_::class, 'object' => \phpDocumentor\Reflection\Types\Object_::class, 'mixed' => \phpDocumentor\Reflection\Types\Mixed_::class, 'array' => \phpDocumentor\Reflection\Types\Array_::class, 'callable-array' => \phpDocumentor\Reflection\PseudoTypes\CallableArray::class, 'array-key' => \phpDocumentor\Reflection\PseudoTypes\ArrayKey::class, 'non-empty-array' => \phpDocumentor\Reflection\PseudoTypes\NonEmptyArray::class, 'resource' => \phpDocumentor\Reflection\Types\Resource_::class, 'open-resource' => \phpDocumentor\Reflection\PseudoTypes\OpenResource::class, 'closed-resource' => \phpDocumentor\Reflection\PseudoTypes\ClosedResource::class, 'void' => \phpDocumentor\Reflection\Types\Void_::class, 'null' => \phpDocumentor\Reflection\Types\Null_::class, 'scalar' => \phpDocumentor\Reflection\PseudoTypes\Scalar::class, 'callback' => \phpDocumentor\Reflection\Types\Callable_::class, 'callable' => \phpDocumentor\Reflection\Types\Callable_::class, 'callable-string' => \phpDocumentor\Reflection\PseudoTypes\CallableString::class, 'false' => \phpDocumentor\Reflection\PseudoTypes\False_::class, 'true' => \phpDocumentor\Reflection\PseudoTypes\True_::class, 'literal-string' => \phpDocumentor\Reflection\PseudoTypes\LiteralString::class, 'self' => \phpDocumentor\Reflection\Types\Self_::class, '$this' => \phpDocumentor\Reflection\Types\This::class, 'static' => \phpDocumentor\Reflection\Types\Static_::class, 'parent' => \phpDocumentor\Reflection\Types\Parent_::class, 'iterable' => \phpDocumentor\Reflection\Types\Iterable_::class, 'never' => \phpDocumentor\Reflection\Types\Never_::class, 'never-return' => \phpDocumentor\Reflection\PseudoTypes\NeverReturn::class, 'never-returns' => \phpDocumentor\Reflection\PseudoTypes\NeverReturns::class, 'no-return' => \phpDocumentor\Reflection\PseudoTypes\NoReturn::class, 'list' => \phpDocumentor\Reflection\PseudoTypes\List_::class, 'non-empty-list' => \phpDocumentor\Reflection\PseudoTypes\NonEmptyList::class, 'non-falsy-string' => \phpDocumentor\Reflection\PseudoTypes\NonFalsyString::class, 'truthy-string' => \phpDocumentor\Reflection\PseudoTypes\TruthyString::class, 'non-positive-int' => \phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger::class, 'non-negative-int' => \phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger::class, 'non-zero-int' => \phpDocumentor\Reflection\PseudoTypes\NonZeroInteger::class]

List of recognized keywords and unto which Value Object they map

Tags
psalm-var

array<string, class-string<Type>>

$typeParser

private TypeParser $typeParser
Tags
psalm-readonly

Methods

__construct()

Initializes this TypeResolver with the means to create and resolve Fqsen objects.

public __construct([FqsenResolver|null $fqsenResolver = null ]) : mixed
Parameters
$fqsenResolver : FqsenResolver|null = null

addKeyword()

Adds a keyword to the list of Keywords and associates it with a specific Value Object.

public addKeyword(string $keyword, string $typeClassName) : void
Parameters
$keyword : string
$typeClassName : string
Tags
psalm-param

class-string<Type> $typeClassName

resolve()

Analyzes the given type and returns the FQCN variant.

public resolve(string $type[, Context|null $context = null ]) : Type

When a type is provided this method checks whether it is not a keyword or Fully Qualified Class Name. If so it will use the given namespace and aliases to expand the type to a FQCN representation.

This method only works as expected if the namespace and aliases are set; no dynamic reflection is being performed here.

Parameters
$type : string

The relative or absolute type.

$context : Context|null = null
Tags
uses
Context::getNamespace()

to determine with what to prefix the type name.

uses
Context::getNamespaceAliases()

to check whether the first part of the relative type name should not be replaced with another namespace.

Return values
Type

createFromGeneric()

private createFromGeneric(GenericTypeNode $type, Context $context) : Type
Parameters
$type : GenericTypeNode
$context : Context
Return values
Type

createTypesByTypeNodes()

private createTypesByTypeNodes(array<string|int, TypeNode$nodes, Context $context) : array<string|int, Type>
Parameters
$nodes : array<string|int, TypeNode>
$context : Context
Return values
array<string|int, Type>

isFqsen()

Tests whether the given type is a Fully Qualified Structural Element Name.

private isFqsen(string $type) : bool
Parameters
$type : string
Tags
psalm-mutation-free
Return values
bool

isKeyword()

Detects whether the given type represents a PHPDoc keyword.

private isKeyword(string $type) : bool
Parameters
$type : string

A relative or absolute type as defined in the phpDocumentor documentation.

Tags
psalm-mutation-free
Return values
bool

isPartialStructuralElementName()

Detects whether the given type represents a relative structural element name.

private isPartialStructuralElementName(string $type) : bool
Parameters
$type : string

A relative or absolute type as defined in the phpDocumentor documentation.

Tags
psalm-mutation-free
Return values
bool

parse()

private parse(TokenIterator $tokenIterator) : TypeNode
Parameters
$tokenIterator : TokenIterator
Return values
TypeNode

resolveKeyword()

Resolves the given keyword (such as `string`) into a Type object representing that keyword.

private resolveKeyword(string $type) : Type
Parameters
$type : string
Tags
psalm-mutation-free
Return values
Type

resolveTypedObject()

Resolves the given FQSEN string into an FQSEN object.

private resolveTypedObject(string $type[, Context|null $context = null ]) : Object_
Parameters
$type : string
$context : Context|null = null
Tags
psalm-mutation-free
Return values
Object_

        
On this page

Search results