NodeHelpers
final class NodeHelpers
Utility functions for working with AST nodes.
Methods
static array
static Node|null
static mixed
toValue(ExpressionNode $node, bool $constants = false)
Evaluates a scalar expression node to a PHP value. Resolves constants when $constants is true.
static string|null
toText(Node|null $node)
Extracts plain text from a node if it contains only static text, or returns null.
Details
at line 27
static array
find(Node $node, callable $filter)
Finds all nodes matching the filter and returns them in traversal order.
at line 44
static Node|null
findFirst(Node $node, callable $filter)
Finds the first node matching the filter, or null if none.
at line 72
static mixed
toValue(ExpressionNode $node, bool $constants = false)
Evaluates a scalar expression node to a PHP value. Resolves constants when $constants is true.
Throws InvalidArgumentException if the expression cannot be reduced to a value.
at line 132
static string|null
toText(Node|null $node)
Extracts plain text from a node if it contains only static text, or returns null.