Skip to content

Add NodeAwareInterface exposing getNode() on all parsed reflections - #200

Merged
lisachenko merged 1 commit into
masterfrom
claude/parser-reflection-182-7f2576
Jul 30, 2026
Merged

Add NodeAwareInterface exposing getNode() on all parsed reflections#200
lisachenko merged 1 commit into
masterfrom
claude/parser-reflection-182-7f2576

Conversation

@lisachenko

Copy link
Copy Markdown
Member

Implements #195: introduces Go\ParserReflection\NodeAwareInterface so clients have an official, discoverable API for accessing the underlying AST node of any parsed reflection.

Changes

New src/NodeAwareInterface.php

interface NodeAwareInterface
{
    public function getNode(): Node;
}

implements NodeAwareInterface added to all 11 node-wrapping reflection classes

All of these already had a getNode() method with a narrowed return type, so this is a declaration-only change — no method bodies were touched. Each class narrows the return type via covariance:

Class getNode() return type
ReflectionClass ClassLike
ReflectionEnum Enum_
ReflectionEnumUnitCase / ReflectionEnumBackedCase EnumCase
ReflectionMethod ClassMethod
ReflectionFunction Function_
ReflectionParameter Param
ReflectionProperty PropertyItem|Param
ReflectionClassConstant ClassConst|EnumCase
ReflectionAttribute Node\Attribute
ReflectionFileNamespace Namespace_

Deliberately not implemented on:

  • ReflectionFile — holds a Node[] list of top-level nodes, no single underlying node to return covariantly
  • ReflectionType / ReflectionNamedType / ReflectionUnionType / ReflectionIntersectionType — built from already-resolved data by TypeExpressionResolver; they store no AST node

New tests/NodeAwareInterfaceTest.php

12 tests asserting each reflection kind implements the interface and returns its expected concrete node type, built from the existing stubs FileWithClasses81.php and FileWithFunction80.php.

Verification

  • vendor/bin/phpunit: 13,685 tests, 14,785 assertions, 0 failures
  • vendor/bin/phpstan analyse src: 0 errors

Closes #195

🤖 Generated with Claude Code

https://claude.ai/code/session_01NDeyey11xvinYJshLsA4Tn


Generated by Claude Code

…ions

Introduces Go\ParserReflection\NodeAwareInterface with a single
getNode(): Node method and implements it on all 11 parsed reflection
classes that wrap an AST node. Each class narrows the return type via
covariance to its concrete node type (ClassLike, ClassMethod, Param,
EnumCase, etc.), making direct AST access an official client API.

Closes #195

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NDeyey11xvinYJshLsA4Tn
@lisachenko
lisachenko marked this pull request as ready for review July 30, 2026 05:49
@lisachenko lisachenko added this to the 4.0.0 milestone Jul 30, 2026
@lisachenko
lisachenko merged commit 13c14b2 into master Jul 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

[Feature] Add node-aware interface to all parsed reflection classes

2 participants