Copied!

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.

  • see \Contextfor more information.
CloneableFinalInstantiable
Methods
public createForNamespace(string $namespace, string $fileContents) : phpDocumentor\Reflection\Types\Context
 

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

  • see \Contextfor more information on Contexts.
  • param string $namespace It does not matter if a \ precedes the namespace name, this method first normalizes.
  • param string $fileContents The file's contents to retrieve the aliases from with the given namespace.
public createFromReflector(Reflector $reflector) : phpDocumentor\Reflection\Types\Context
 

Build a Context given a Class Reflection.

  • see \Contextfor more information on Contexts.
Constants
private phpDocumentor\Reflection\Types\ContextFactory::T_LITERAL_END_OF_USE = ';'
 

The literal used at the end of a use statement.

private phpDocumentor\Reflection\Types\ContextFactory::T_LITERAL_USE_SEPARATOR = ','
 

The literal used between sets of use statements

Methods
private createFromReflectionClass(ReflectionClass $class) : phpDocumentor\Reflection\Types\Context
 
  • phpstan-param ReflectionClass<object> $class
private createFromReflectionClassConstant(ReflectionClassConstant $constant) : phpDocumentor\Reflection\Types\Context
private createFromReflectionMethod(ReflectionMethod $method) : phpDocumentor\Reflection\Types\Context
private createFromReflectionParameter(ReflectionParameter $parameter) : phpDocumentor\Reflection\Types\Context
private createFromReflectionProperty(ReflectionProperty $property) : phpDocumentor\Reflection\Types\Context
private extractUseStatements(ArrayIterator $tokens) : array
 

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.

  • param \ArrayIterator<int,string|array{0: int, 1: string, 2: int}> $tokens
  • return string[]
  • psalm-return array<string, string>
  • psalm-suppress TypeDoesNotContainType
private parseNamespace(ArrayIterator $tokens) : string
 

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

  • param \ArrayIterator<int,string|array{0: int, 1: string, 2: int}> $tokens
private parseUseStatement(ArrayIterator $tokens) : array
 

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

  • param \ArrayIterator<int,string|array{0: int, 1: string, 2: int}> $tokens
  • return string[]
  • psalm-return array<string, string>
private skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : void
 

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

  • param \ArrayIterator<int,string|array{0: int, 1: string, 2: int}> $tokens
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration