Skip to content

Index class-likes declared inside conditional blocks#154

Open
MrSrsen wants to merge 1 commit into
PHPantom-dev:mainfrom
MrSrsen:fix/conditional-class-indexing
Open

Index class-likes declared inside conditional blocks#154
MrSrsen wants to merge 1 commit into
PHPantom-dev:mainfrom
MrSrsen:fix/conditional-class-indexing

Conversation

@MrSrsen

@MrSrsen MrSrsen commented Jun 8, 2026

Copy link
Copy Markdown

Fixes: #153

A named class/interface/trait/enum declared inside an if/else (or try/ switch/loop) block — e.g. Doctrine's ServiceEntityRepository, defined per ORM version inside an 'if (! property_exists(...))' guard — was discovered by name only: its parent and @extends/@template-extends generics were dropped, so the inheritance/generic chain collapsed ($repo->find() resolved to object/mixed instead of the entity).

Descend into container-statement bodies when extracting class-likes (parser/classes.rs), route top-level containers through the extractor (parser/mod.rs, parser/ast_update.rs), and keep the first declaration when the same FQN appears in multiple branches (first-occurrence-wins, matching PHPStan/Psalm and the existing classmap convention).

Adds unit tests + an assert_type regression fixture.

A named class/interface/trait/enum declared inside an if/else (or try/
switch/loop) block — e.g. Doctrine's ServiceEntityRepository, defined per
ORM version inside an 'if (! property_exists(...))' guard — was discovered
by name only: its parent and @extends/@template-extends generics were
dropped, so the inheritance/generic chain collapsed ($repo->find() resolved
to object/mixed instead of the entity).

Descend into container-statement bodies when extracting class-likes
(parser/classes.rs), route top-level containers through the extractor
(parser/mod.rs, parser/ast_update.rs), and keep the first declaration when
the same FQN appears in multiple branches (first-occurrence-wins, matching
PHPStan/Psalm and the existing classmap convention).

Adds unit tests + an assert_type regression fixture.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

Classes declared inside conditional blocks (if/else) are not indexed for type resolution — breaks Doctrine ServiceEntityRepository generic chain

2 participants