Type Resolver

ContextFactory
in package

FinalYes

Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor.

For a DocBlock to be able to resolve types that use partial namespace names or rely on namespace imports we need to provide a bit of context so that the DocBlock can read that and based on it decide how to resolve the types to Fully Qualified names.

Tags
see
Context

for more information.

Table of Contents

Constants

T_LITERAL_END_OF_USE  = ';'
The literal used at the end of a use statement.
T_LITERAL_USE_SEPARATOR  = ','
The literal used between sets of use statements

Methods

createForNamespace()  : Context
Build a Context for a namespace in the provided file contents.
createFromReflector()  : Context
Build a Context given a Class Reflection.
createFromReflectionClass()  : Context
createFromReflectionClassConstant()  : Context
createFromReflectionMethod()  : Context
createFromReflectionParameter()  : Context
createFromReflectionProperty()  : Context
extractUseStatements()  : array<string|int, string>
Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of a USE statement yet. This will return a key/value array of the alias => namespace.
parseNamespace()  : string
Deduce the name from tokens when we are at the T_NAMESPACE token.
parseUseStatement()  : array<string|int, string>
Deduce the names of all imports when we are at the T_USE token.
skipToNextStringOrNamespaceSeparator()  : void
Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token.

Constants

T_LITERAL_END_OF_USE

The literal used at the end of a use statement.

private mixed T_LITERAL_END_OF_USE = ';'

T_LITERAL_USE_SEPARATOR

The literal used between sets of use statements

private mixed T_LITERAL_USE_SEPARATOR = ','

Methods

createForNamespace()

Build a Context for a namespace in the provided file contents.

public createForNamespace(string $namespace, string $fileContents) : Context
Parameters
$namespace : string

It does not matter if a \ precedes the namespace name, this method first normalizes.

$fileContents : string

The file's contents to retrieve the aliases from with the given namespace.

Tags
see
Context

for more information on Contexts.

Return values
Context

createFromReflector()

Build a Context given a Class Reflection.

public createFromReflector(Reflector $reflector) : Context
Parameters
$reflector : Reflector
Tags
see
Context

for more information on Contexts.

Return values
Context

createFromReflectionClass()

private createFromReflectionClass(ReflectionClass $class) : Context
Parameters
$class : ReflectionClass
Tags
phpstan-param

ReflectionClass $class

Return values
Context

createFromReflectionClassConstant()

private createFromReflectionClassConstant(ReflectionClassConstant $constant) : Context
Parameters
$constant : ReflectionClassConstant
Return values
Context

createFromReflectionMethod()

private createFromReflectionMethod(ReflectionMethod $method) : Context
Parameters
$method : ReflectionMethod
Return values
Context

createFromReflectionParameter()

private createFromReflectionParameter(ReflectionParameter $parameter) : Context
Parameters
$parameter : ReflectionParameter
Return values
Context

createFromReflectionProperty()

private createFromReflectionProperty(ReflectionProperty $property) : Context
Parameters
$property : ReflectionProperty
Return values
Context

extractUseStatements()

Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of a USE statement yet. This will return a key/value array of the alias => namespace.

private extractUseStatements(ArrayIterator<int, string|array{0: int, 1: string, 2: int}> $tokens) : array<string|int, string>
Parameters
$tokens : ArrayIterator<int, string|array{0: int, 1: string, 2: int}>
Tags
psalm-return

array<string, string>

psalm-suppress

TypeDoesNotContainType

Return values
array<string|int, string>

parseNamespace()

Deduce the name from tokens when we are at the T_NAMESPACE token.

private parseNamespace(ArrayIterator<int, string|array{0: int, 1: string, 2: int}> $tokens) : string
Parameters
$tokens : ArrayIterator<int, string|array{0: int, 1: string, 2: int}>
Return values
string

parseUseStatement()

Deduce the names of all imports when we are at the T_USE token.

private parseUseStatement(ArrayIterator<int, string|array{0: int, 1: string, 2: int}> $tokens) : array<string|int, string>
Parameters
$tokens : ArrayIterator<int, string|array{0: int, 1: string, 2: int}>
Tags
psalm-return

array<string, string>

Return values
array<string|int, string>

skipToNextStringOrNamespaceSeparator()

Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token.

private skipToNextStringOrNamespaceSeparator(ArrayIterator<int, string|array{0: int, 1: string, 2: int}> $tokens) : void
Parameters
$tokens : ArrayIterator<int, string|array{0: int, 1: string, 2: int}>

        
On this page

Search results