UseStatementPass
extends CodeCleanerPass
in package
Provide implicit use statements for subsequent execution.
The use statement pass remembers the last use statement line encountered:
use Foo\Bar as Baz;
... which it then applies implicitly to all future evaluated code, until the current namespace is replaced by another namespace.
Table of Contents
- $aliases : mixed
- $lastAliases : mixed
- $lastNamespace : mixed
- afterTraverse() : null|array<string|int, Node>
- Called once after traversal.
- beforeTraverse() : null|array<string|int, Node>
- Called once before traversal.
- enterNode() : mixed
- Re-load the last set of use statements on re-entering a namespace.
- leaveNode() : mixed
- If this statement is a namespace, forget all the aliases we had.
- findAlias() : FullyQualified|null
- Find class/namespace aliases.
Properties
$aliases
private
mixed
$aliases
= []
$lastAliases
private
mixed
$lastAliases
= []
$lastNamespace
private
mixed
$lastNamespace
= null
Methods
afterTraverse()
Called once after traversal.
public
afterTraverse(array<string|int, mixed> $nodes) : null|array<string|int, Node>
Return value semantics:
- null: $nodes stays as-is
- otherwise: $nodes is set to the return value
Parameters
- $nodes : array<string|int, mixed>
-
Array of nodes
Return values
null|array<string|int, Node> —Array of nodes
beforeTraverse()
Called once before traversal.
public
beforeTraverse(array<string|int, mixed> $nodes) : null|array<string|int, Node>
Return value semantics:
- null: $nodes stays as-is
- otherwise: $nodes is set to the return value
Parameters
- $nodes : array<string|int, mixed>
-
Array of nodes
Return values
null|array<string|int, Node> —Array of nodes
enterNode()
Re-load the last set of use statements on re-entering a namespace.
public
enterNode(Node $node) : mixed
This isn't how namespaces normally work, but because PsySH has to spin up a new namespace for every line of code, we do this to make things work like you'd expect.
Parameters
- $node : Node
Return values
mixed —leaveNode()
If this statement is a namespace, forget all the aliases we had.
public
leaveNode(Node $node) : mixed
If it's a use statement, remember the alias for later. Otherwise, apply remembered aliases to the code.
Parameters
- $node : Node
Return values
mixed —findAlias()
Find class/namespace aliases.
private
findAlias(Name $name) : FullyQualified|null
Parameters
- $name : Name