Documentation

TypeResolver
in package

Table of Contents

OPERATOR_NAMESPACE  = '\'
$fqsenResolver  : FqsenResolver
$keywords  : array<string, string>
$lexer  : Lexer
$typeParser  : TypeParser
__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.
createArray()  : Array_
createFromCallable()  : Callable_
createFromConst()  : Type
createFromGeneric()  : 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.
tryParseRemainingCompoundTypes()  : Type
Will try to parse unsupported type notations by phpstan
validArrayKeyType()  : bool

Constants

OPERATOR_NAMESPACE

private string OPERATOR_NAMESPACE = '\'

Definition of the NAMESPACE operator in PHP

Properties

$keywords

private array<string, string> $keywords = ['string' => phpDocumentorReflectionTypesString_::class, 'class-string' => phpDocumentorReflectionTypesClassString::class, 'interface-string' => phpDocumentorReflectionTypesInterfaceString::class, 'html-escaped-string' => phpDocumentorReflectionPseudoTypesHtmlEscapedString::class, 'lowercase-string' => phpDocumentorReflectionPseudoTypesLowercaseString::class, 'non-empty-lowercase-string' => phpDocumentorReflectionPseudoTypesNonEmptyLowercaseString::class, 'non-empty-string' => phpDocumentorReflectionPseudoTypesNonEmptyString::class, 'numeric-string' => phpDocumentorReflectionPseudoTypesNumericString::class, 'numeric' => phpDocumentorReflectionPseudoTypesNumeric_::class, 'trait-string' => phpDocumentorReflectionPseudoTypesTraitString::class, 'int' => phpDocumentorReflectionTypesInteger::class, 'integer' => phpDocumentorReflectionTypesInteger::class, 'positive-int' => phpDocumentorReflectionPseudoTypesPositiveInteger::class, 'negative-int' => phpDocumentorReflectionPseudoTypesNegativeInteger::class, 'bool' => phpDocumentorReflectionTypesBoolean::class, 'boolean' => phpDocumentorReflectionTypesBoolean::class, 'real' => phpDocumentorReflectionTypesFloat_::class, 'float' => phpDocumentorReflectionTypesFloat_::class, 'double' => phpDocumentorReflectionTypesFloat_::class, 'object' => phpDocumentorReflectionTypesObject_::class, 'mixed' => phpDocumentorReflectionTypesMixed_::class, 'array' => phpDocumentorReflectionTypesArray_::class, 'array-key' => phpDocumentorReflectionTypesArrayKey::class, 'resource' => phpDocumentorReflectionTypesResource_::class, 'void' => phpDocumentorReflectionTypesVoid_::class, 'null' => phpDocumentorReflectionTypesNull_::class, 'scalar' => phpDocumentorReflectionTypesScalar::class, 'callback' => phpDocumentorReflectionTypesCallable_::class, 'callable' => phpDocumentorReflectionTypesCallable_::class, 'callable-string' => phpDocumentorReflectionPseudoTypesCallableString::class, 'false' => phpDocumentorReflectionPseudoTypesFalse_::class, 'true' => phpDocumentorReflectionPseudoTypesTrue_::class, 'literal-string' => phpDocumentorReflectionPseudoTypesLiteralString::class, 'self' => phpDocumentorReflectionTypesSelf_::class, '$this' => phpDocumentorReflectionTypesThis::class, 'static' => phpDocumentorReflectionTypesStatic_::class, 'parent' => phpDocumentorReflectionTypesParent_::class, 'iterable' => phpDocumentorReflectionTypesIterable_::class, 'never' => phpDocumentorReflectionTypesNever_::class, 'list' => phpDocumentorReflectionPseudoTypesList_::class, 'non-empty-list' => phpDocumentorReflectionPseudoTypesNonEmptyList::class]

List of recognized keywords and unto which Value Object they map

Tags
psalm-var

array<string, class-string>

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
Return values
mixed

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 $typeClassName

Return values
void

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

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

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

resolveSingleType()

resolve the given type into a type object

private resolveSingleType(string $type, Context $context) : Type|Array_|Object_
Parameters
$type : string

the type string, representing a single type

$context : Context
Tags
psalm-mutation-free
Return values
Type|Array_|Object_

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_

tryParseRemainingCompoundTypes()

Will try to parse unsupported type notations by phpstan

private tryParseRemainingCompoundTypes(TokenIterator $tokenIterator, Context $context, Type $type) : Type

The phpstan parser doesn't support the illegal nullable combinations like this library does. This method will warn the user about those notations but for bc purposes we will still have it here.

Parameters
$tokenIterator : TokenIterator
$context : Context
$type : Type
Return values
Type

validArrayKeyType()

private validArrayKeyType(Type|null $type) : bool
Parameters
$type : Type|null
Return values
bool

Search results