final class NodeHelpers

Utility functions for working with AST nodes.

Methods

static array
find(Node $node, callable $filter)

Finds all nodes matching the filter and returns them in traversal order.

static Node|null
findFirst(Node $node, callable $filter)

Finds the first node matching the filter, or null if none.

static Node
clone(Node $node)

Creates a deep clone of the node tree.

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.

Parameters

Node $node
callable $filter

Return Value

array

at line 44
static Node|null findFirst(Node $node, callable $filter)

Finds the first node matching the filter, or null if none.

Parameters

Node $node
callable $filter

Return Value

Node|null

at line 61
static Node clone(Node $node)

Creates a deep clone of the node tree.

Parameters

Node $node

Return Value

Node

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.

Parameters

ExpressionNode $node
bool $constants

Return Value

mixed

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.

Parameters

Node|null $node

Return Value

string|null