Skip to content

Extract statement handling from NodeScopeResolver into StmtHandler classes - #6247

Merged
ondrejmirtes merged 7 commits into
2.2.xfrom
stmt-handler
Aug 23, 2026
Merged

ondrejmirtes merged 7 commits into
2.2.xfrom
stmt-handler

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Extracts per-statement analysis out of NodeScopeResolver into dedicated StmtHandler classes, mirroring the existing ExprHandler architecture. Pure code move — every moved line comes from NodeScopeResolver verbatim (modulo the mechanical transforms below); analysis output is unchanged.

What's in here

Commit 1 — Introduce StmtHandler

  • StmtHandler interface (#[ExtensionInterface(tag: 'phpstan.stmtHandler')], @template T of Stmt) + StmtHandlerRegistry (per-container resolution memoized by statement class).
  • 32 handlers under src/Analyser/StmtHandler/ (If, Foreach, For, While, DoWhile, Switch, TryCatch, Return, Expression, Echo, Unset, ClassLike, ClassMethod, Function, Property, TraitUse, …).
  • NodeScopeResolver::processStmtNode() becomes a dispatcher; NodeScopeResolver shrinks from ~5800 to ~3200 lines.
  • Mechanical transforms in moved code: $this->x(...)$nodeScopeResolver->x(...) for NSR APIs (NSR is passed to processStmt()), constructor state read through accessors, plain services injected into handler constructors.
  • One deliberate unification: $overridingThrowPoints is now applied centrally by the dispatcher instead of per statement branch.

Commits 2–7 — service extractions
Non-@api public NodeScopeResolver methods used only by handlers move into their own #[AutowiredService] classes, together with their private dependencies: PropertyHookThrowPointsResolver, VarAnnotationProcessor, CalledMethodProcessor (takes the called-method stack/results state with it), PropertyHooksProcessor, PhpDocsResolver (PhpClassReflectionExtension now injects it instead of the whole NodeScopeResolver), DeprecatedAttributeResolver.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GnwgpaeUXRkgSDyg95tfK8

ondrejmirtes and others added 7 commits August 23, 2026 19:19
Statement processing moves out of NodeScopeResolver's processStmtNode
if-chain into per-statement StmtHandler classes, dispatched through
StmtHandlerRegistry (memoized by statement class, mirroring
ExprHandlerRegistry). Overriding @throws points are applied centrally by
the dispatcher, so handlers return their computed throw points plainly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GnwgpaeUXRkgSDyg95tfK8
PhpClassReflectionExtension no longer needs the whole NodeScopeResolver -
it injects the PhpDocsResolver it actually uses.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GnwgpaeUXRkgSDyg95tfK8
@ondrejmirtes
ondrejmirtes merged commit b9e8123 into 2.2.x Aug 23, 2026
756 of 761 checks passed
@ondrejmirtes
ondrejmirtes deleted the stmt-handler branch August 23, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant