ValidClassNamePass
extends NamespaceAwarePass
in package
Validate that classes exist.
This pass throws a FatalErrorException rather than letting PHP run headfirst into a real fatal error and die.
Table of Contents
- CLASS_TYPE = 'class'
- INTERFACE_TYPE = 'interface'
- TRAIT_TYPE = 'trait'
- $currentScope : mixed
- $namespace : mixed
- $atLeastPhp55 : mixed
- $conditionalScopes : mixed
- __construct() : mixed
- afterTraverse() : null|array<string|int, Node>
- Called once after traversal.
- beforeTraverse() : null|array<string|int, Node>
- Called once before traversal.
- enterNode() : mixed
- Validate class, interface and trait definitions.
- leaveNode() : mixed
- Validate `new` expressions, class constant fetches, and static calls.
- classExists() : bool
- Check whether a class exists, or has been defined in the current code snippet.
- createError() : FatalErrorException
- Error creation factory.
- ensureCanDefine() : mixed
- Ensure that no class, interface or trait name collides with a new definition.
- ensureClassExists() : mixed
- Ensure that a referenced class exists.
- ensureClassOrInterfaceExists() : mixed
- Ensure that a referenced class _or interface_ exists.
- ensureClassOrTraitExists() : mixed
- Ensure that a referenced class _or trait_ exists.
- ensureInterfacesExist() : mixed
- Ensure that a referenced interface exists.
- ensureMethodExists() : mixed
- Ensure that a statically called method exists.
- findInScope() : string|null
- Find a symbol in the current code snippet scope.
- getFullyQualifiedName() : string
- Get a fully-qualified name (class, function, interface, etc).
- getScopeType() : string
- Get a symbol type key for storing in the scope name cache.
- interfaceExists() : bool
- Check whether an interface exists, or has been defined in the current code snippet.
- traitExists() : bool
- Check whether a trait exists, or has been defined in the current code snippet.
- validateClassConstFetchExpression() : mixed
- Validate a class constant fetch expression's class.
- validateClassStatement() : mixed
- Validate a class definition statement.
- validateInterfaceStatement() : mixed
- Validate an interface definition statement.
- validateNewExpression() : mixed
- Validate a `new` expression.
- validateStaticCallExpression() : mixed
- Validate a class constant fetch expression's class.
- validateTraitStatement() : mixed
- Validate a trait definition statement.
- isConditional() : mixed
Constants
CLASS_TYPE
public
mixed
CLASS_TYPE
= 'class'
INTERFACE_TYPE
public
mixed
INTERFACE_TYPE
= 'interface'
TRAIT_TYPE
public
mixed
TRAIT_TYPE
= 'trait'
Properties
$currentScope
protected
mixed
$currentScope
$namespace
protected
mixed
$namespace
$atLeastPhp55
private
mixed
$atLeastPhp55
$conditionalScopes
private
mixed
$conditionalScopes
= 0
Methods
__construct()
public
__construct() : mixed
Return values
mixed —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()
Validate class, interface and trait definitions.
public
enterNode(Node $node) : mixed
Validate them upon entering the node, so that we know about their presence and can validate constant fetches and static calls in class or trait methods.
Parameters
- $node : Node
Return values
mixed —leaveNode()
Validate `new` expressions, class constant fetches, and static calls.
public
leaveNode(Node $node) : mixed
Parameters
- $node : Node
Tags
Return values
mixed —classExists()
Check whether a class exists, or has been defined in the current code snippet.
protected
classExists(string $name) : bool
Gives self, static and parent a free pass.
Parameters
- $name : string
Return values
bool —createError()
Error creation factory.
protected
createError(string $msg, Stmt $stmt) : FatalErrorException
Parameters
- $msg : string
- $stmt : Stmt
Return values
FatalErrorException —ensureCanDefine()
Ensure that no class, interface or trait name collides with a new definition.
protected
ensureCanDefine(Stmt $stmt[, string $scopeType = self::CLASS_TYPE ]) : mixed
Parameters
- $stmt : Stmt
- $scopeType : string = self::CLASS_TYPE
Tags
Return values
mixed —ensureClassExists()
Ensure that a referenced class exists.
protected
ensureClassExists(string $name, Stmt $stmt) : mixed
Parameters
- $name : string
- $stmt : Stmt
Tags
Return values
mixed —ensureClassOrInterfaceExists()
Ensure that a referenced class _or interface_ exists.
protected
ensureClassOrInterfaceExists(string $name, Stmt $stmt) : mixed
Parameters
- $name : string
- $stmt : Stmt
Tags
Return values
mixed —ensureClassOrTraitExists()
Ensure that a referenced class _or trait_ exists.
protected
ensureClassOrTraitExists(string $name, Stmt $stmt) : mixed
Parameters
- $name : string
- $stmt : Stmt
Tags
Return values
mixed —ensureInterfacesExist()
Ensure that a referenced interface exists.
protected
ensureInterfacesExist(array<string|int, Interface_> $interfaces, Stmt $stmt) : mixed
Parameters
- $interfaces : array<string|int, Interface_>
- $stmt : Stmt
Tags
Return values
mixed —ensureMethodExists()
Ensure that a statically called method exists.
protected
ensureMethodExists(string $class, string $name, Stmt $stmt) : mixed
Parameters
- $class : string
- $name : string
- $stmt : Stmt
Tags
Return values
mixed —findInScope()
Find a symbol in the current code snippet scope.
protected
findInScope(string $name) : string|null
Parameters
- $name : string
Return values
string|null —getFullyQualifiedName()
Get a fully-qualified name (class, function, interface, etc).
protected
getFullyQualifiedName(mixed $name) : string
Parameters
- $name : mixed
Return values
string —getScopeType()
Get a symbol type key for storing in the scope name cache.
protected
getScopeType(Stmt $stmt) : string
Parameters
- $stmt : Stmt
Tags
Return values
string —interfaceExists()
Check whether an interface exists, or has been defined in the current code snippet.
protected
interfaceExists(string $name) : bool
Parameters
- $name : string
Return values
bool —traitExists()
Check whether a trait exists, or has been defined in the current code snippet.
protected
traitExists(string $name) : bool
Parameters
- $name : string
Return values
bool —validateClassConstFetchExpression()
Validate a class constant fetch expression's class.
protected
validateClassConstFetchExpression(ClassConstFetch $stmt) : mixed
Parameters
- $stmt : ClassConstFetch
Return values
mixed —validateClassStatement()
Validate a class definition statement.
protected
validateClassStatement(Class_ $stmt) : mixed
Parameters
- $stmt : Class_
Return values
mixed —validateInterfaceStatement()
Validate an interface definition statement.
protected
validateInterfaceStatement(Interface_ $stmt) : mixed
Parameters
- $stmt : Interface_
Return values
mixed —validateNewExpression()
Validate a `new` expression.
protected
validateNewExpression(New_ $stmt) : mixed
Parameters
- $stmt : New_
Return values
mixed —validateStaticCallExpression()
Validate a class constant fetch expression's class.
protected
validateStaticCallExpression(StaticCall $stmt) : mixed
Parameters
- $stmt : StaticCall
Return values
mixed —validateTraitStatement()
Validate a trait definition statement.
protected
validateTraitStatement(Trait_ $stmt) : mixed
Parameters
- $stmt : Trait_
Return values
mixed —isConditional()
private
static isConditional(Node $node) : mixed
Parameters
- $node : Node