MatcherVisitor
MatcherVisitor is the generic base behind ClassNameMatcherVisitor. Use it directly when the condition you're searching for is more than just "is an instance of this class".
$matcher— called for every node; the first node for which it returnstruebecomes the match, and traversal of that subtree stops there (Command::SkipChildrenis returned automatically once found, and for every node visited afterwards).$break— optional early-exit predicate, checked whenever$matcheritself didn't match; if it returnstrue, the search stops there (leavingnodeasnull) without visiting the rest of the tree.
After a traverse() call, $matcher->node holds the matched node (or null), and $matcher->isFound is a convenience boolean for the same.
Example
Find the first named type whose name is longer than a given length:
Stopping Early with $break
The $break callback lets you bail out before scanning the whole tree once some other condition is met — useful when you know the node you're looking for can't possibly occur past a certain point:
ClassNameMatcherVisitor(SomeClass::class) is exactly new MatcherVisitor(static fn(Node $node): bool => $node instanceof SomeClass) with no $break — reach for it directly whenever an instanceof check is all you need.