final class SourceTree
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Where a node sits in the source: which statement list holds it, and which file.

Walking back from a call means walking back through the statement lists it is nested in, so every statement has to be able to say which list it sits in and at what position. A statement inside a body says so through its parent; a statement at the top of a file has no parent, and is found here instead.

Methods§

public function __construct(list<ParsedFile> $files = [])

Records the top level of every file.

Parameters

$fileslist<ParsedFile>
Calls 1
public function anchorOf(Node $node): Stmt|FunctionLike|null

The statement a node is part of, or the function-like whose expression body holds it.

An arrow function has no statements, so a call written in one stops at the arrow function itself rather than at the statement that defines it: the arrow function's parameters are its own, not the enclosing body's.

Parameters

$nodeNode

Returns

Stmt|FunctionLike|null
Test cases 3
Called from 2
Calls 2
public function isListed(Stmt $statement): bool

Whether a statement sits in a list of statements that run one after another.

The arms of a conditional, a switch or a try are statements too, but they sit in the statement that owns them rather than in a list that runs.

Parameters

$statementStmt

Returns

bool
Test cases 1
Called from 1
Calls 1
  • method-call Stmt::getAttribute() line 87
public function locate(Stmt $statement): array{Node|null, list<Stmt>, int}|null

The node that owns the list a statement sits in, the list, and the statement's position in it.

Parameters

$statementStmt

Returns

array{Node|null, list<Stmt>, int}|null
Test cases 3
Called from 1
Calls 4
public function listOf(Node $parent): list<Stmt>

The statements a node runs one after another, or an empty list when it runs none.

Parameters

$parentNode

Returns

list<Stmt>
Test cases 1
Called from 1
Calls 2
public function fileOf(Node $node): string

The file a node is written in, or an empty string when it is not in any recorded file.

Parameters

$nodeNode

Returns

string
Test cases 1
Called from 2
Calls 1
  • method-call Node::getAttribute() line 150

Private surface 2§

Implementation details, listed for orientation only.

private WeakMap<Stmt, array{string, int}> $roots
private array<string, list<Stmt>> $files = []

Test cases 103§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 10
Other tests reaching this symbol 93

Relations§

Instantiated in 1
Method calls 11
Type declarations 4