Skip to content

Rework phpDoc inheritance to resolve through reflection instead of re-walking the hierarchy#4829

Merged
ondrejmirtes merged 3 commits into2.1.xfrom
phpdoc-inherit-resolver
Jan 30, 2026
Merged

Rework phpDoc inheritance to resolve through reflection instead of re-walking the hierarchy#4829
ondrejmirtes merged 3 commits into2.1.xfrom
phpdoc-inherit-resolver

Conversation

@ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Jan 28, 2026

Closes phpstan/phpstan#10771

These changes make PhpDocInheritanceResolver completely disappear from the Blackfire profile:

Screenshot 2026-01-28 at 18 03 51

There are some failing tests but I created a PR so I can look at diffs comfortably and implement again what I deleted.

@ondrejmirtes ondrejmirtes force-pushed the phpdoc-inherit-resolver branch 8 times, most recently from a5cbeeb to 687df1e Compare January 30, 2026 12:06
@ondrejmirtes ondrejmirtes marked this pull request as ready for review January 30, 2026 12:13
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes force-pushed the phpdoc-inherit-resolver branch from 515a43d to 2452137 Compare January 30, 2026 12:16
@ondrejmirtes ondrejmirtes changed the title Rework PhpDocInheritanceResolver to use reflection more and not work … Rework phpDoc inheritance to resolve through reflection instead of re-walking the hierarchy Jan 30, 2026
@ondrejmirtes ondrejmirtes merged commit d584c6e into 2.1.x Jan 30, 2026
92 checks passed
@ondrejmirtes ondrejmirtes deleted the phpdoc-inherit-resolver branch January 30, 2026 12:16
spaze added a commit to spaze/phpstan-disallowed-calls that referenced this pull request Jan 31, 2026
PHPStan 2.1.38 have started adding the types, so instead of e.g. `PhpOption\Option` we got `PhpOption\Option<mixed>` and that didn't match with the configured class for a disallowed constant, causing `ClassConstantUsagesTest` to fail.

I think the change was introduced in phpstan/phpstan-src#4829 because if you look at the changed files, you'll see a lot of `->getDisplayName()` => `->getDisplayName(false)`.
spaze added a commit to spaze/phpstan-disallowed-calls that referenced this pull request Jan 31, 2026
…me (#363)

PHPStan 2.1.38 have started adding the types, so instead of e.g. `PhpOption\Option` we got `PhpOption\Option<mixed>` and that didn't match with the configured class for a disallowed constant, causing `ClassConstantUsagesTest` to fail.

I think the change was introduced in phpstan/phpstan-src#4829 because if you look at the changed files, you'll see a lot of `->getDisplayName()` => `->getDisplayName(false)`.
mglaman added a commit to mglaman/phpstan-src that referenced this pull request Feb 20, 2026
NodeScopeResolver::getPhpDocs() was only consulting FileTypeMapper
(the source file's phpDoc) when resolving parameter types inside method
bodies, never checking StubPhpDocProvider for stub overrides.

This was a regression introduced in 2.1.38 by PR phpstan#4829, which rewrote
PhpDocInheritanceResolver::resolvePhpDocForMethod() and removed the
PhpDocBlock::docBlockToResolvedDocBlock() helper that previously called
StubPhpDocProvider::findMethodPhpDoc() first.

The fix mirrors the pre-regression behaviour: consult StubPhpDocProvider
before falling back to FileTypeMapper in the ClassMethod phpDoc
resolution path of getPhpDocs().

Fixes phpstan/phpstan#14118

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
mglaman added a commit to mglaman/phpstan-src that referenced this pull request Feb 20, 2026
NodeScopeResolver::getPhpDocs() was only consulting FileTypeMapper
(the source file's phpDoc) when resolving parameter types inside method
bodies, never checking StubPhpDocProvider for stub overrides.

This was a regression introduced in 2.1.38 by PR phpstan#4829, which rewrote
PhpDocInheritanceResolver::resolvePhpDocForMethod() and removed the
PhpDocBlock::docBlockToResolvedDocBlock() helper that previously called
StubPhpDocProvider::findMethodPhpDoc() first.

The fix mirrors the pre-regression behaviour: consult StubPhpDocProvider
before falling back to FileTypeMapper in the ClassMethod phpDoc
resolution path of getPhpDocs().

Fixes phpstan/phpstan#14118

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
mglaman added a commit to mglaman/phpstan-drupal that referenced this pull request Feb 25, 2026
PHPStan 2.1.38+ reworked phpDoc inheritance to resolve through
reflection instead of re-walking the hierarchy (phpstan/phpstan-src#4829).
This causes @deprecated annotations on EntityStorageInterface::loadRevision
to propagate through the full class/interface hierarchy, bypassing the
RevisionableStorageInterface stub that was supposed to suppress false
positives.

The test no longer validates the stub's intended behavior, so remove it
and the associated data fixture.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
mglaman added a commit to mglaman/phpstan-drupal that referenced this pull request Feb 25, 2026
Remove RevisionableStorageInterfaceStubTest (#941)

PHPStan 2.1.38+ reworked phpDoc inheritance to resolve through
reflection instead of re-walking the hierarchy (phpstan/phpstan-src#4829).
This causes @deprecated annotations on EntityStorageInterface::loadRevision
to propagate through the full class/interface hierarchy, bypassing the
RevisionableStorageInterface stub that was supposed to suppress false
positives.

The test no longer validates the stub's intended behavior, so remove it
and the associated data fixture.

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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.

Method should return class-string<T of Template> but returns class-string<T of Template>

2 participants