Documentation

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

Properties

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()

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
throws
FatalErrorException

if a class, interface or trait is referenced which does not exist

throws
FatalErrorException

if a class extends something that is not a class

throws
FatalErrorException

if a class implements something that is not an interface

throws
FatalErrorException

if an interface extends something that is not an interface

throws
FatalErrorException

if a class, interface or trait redefines an existing class, interface or trait name

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

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

ensureClassExists()

Ensure that a referenced class exists.

protected ensureClassExists(string $name, Stmt $stmt) : mixed
Parameters
$name : string
$stmt : Stmt
Tags
throws
FatalErrorException
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
throws
FatalErrorException
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
throws
FatalErrorException
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
throws
FatalErrorException
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
deprecated

No longer used. Scope type should be passed into ensureCanDefine directly.

codeCoverageIgnore
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

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

Search results