Noir::PhpBlockParser
The block structure of PHP source, read off a PhpLexer's masked text
(strings, comments, heredocs and inline HTML blanked), so no delimiter or
keyword inside a literal or a comment can open, close or fake a block.
One linear pass builds a tree of the constructs analyzers ask about:
- statements:
if/elseif/elsechains,try/catch/finally,switchand itscases, loops, bare{ }blocks, with each construct's parenthesised head (condition, subject) as a span; - code units: named functions, methods, closures (
function () use () { }) and arrow functions (fn () => expr), with their parameter lists, andmatchexpressions — also when they sit inside an argument list or another construct's condition; - declarations:
class/trait/interface/enum(andnew class) with their methods and properties as members; - PHP 8 attributes
#[A(...), B], attached to the declaration they precede.
Every delimiter pair is matched once up front, so the tree, close_of
and array_entries all answer without rescanning. Ranges are character
offsets into the lexed source (same as PhpLexer#masked); a block's
body excludes its braces.
Constants
The words that end an alternative-syntax body (if (x): ... endif;).
Constructors
Instance methods
Elements of the array literal whose [ (or array('s () is at
open, or nil when it does not close.
class / trait / interface / enum declarations outside any
function: at the top level, in a namespace { } block, or declared
under a condition (if (! class_exists(X::class)) { class X ... }).