Skip to content

Fix stub @param types not applied inside method bodies (regression since 2.1.38)#5007

Closed
mglaman wants to merge 3613 commits intophpstan:1.11.xfrom
mglaman:fix/stub-param-types-in-method-bodies
Closed

Fix stub @param types not applied inside method bodies (regression since 2.1.38)#5007
mglaman wants to merge 3613 commits intophpstan:1.11.xfrom
mglaman:fix/stub-param-types-in-method-bodies

Conversation

@mglaman
Copy link
Copy Markdown
Contributor

@mglaman mglaman commented Feb 20, 2026

Summary

  • Fixes NodeScopeResolver::getPhpDocs() to consult StubPhpDocProvider before falling back to FileTypeMapper when resolving parameter types inside method bodies
  • Adds StubPhpDocProvider as a constructor parameter to NodeScopeResolver
  • Updates all direct NodeScopeResolver constructor call sites in test infrastructure to include the new parameter

Problem

Since 2.1.38 (PR #4829 — "Rework phpDoc inheritance to resolve through reflection instead of re-walking the hierarchy"), stub @param type overrides were silently ignored inside method bodies. External callers of a stubbed method still saw the correct stub types, but the method's own body would use the source file's @param type instead.

Root cause: The removed PhpDocBlock::docBlockToResolvedDocBlock() helper previously called StubPhpDocProvider::findMethodPhpDoc() first and fell back to FileTypeMapper only if no stub was found. The rewritten path in getPhpDocs() only consulted FileTypeMapper, never checking stubs.

Fixes phpstan/phpstan#14118

Test plan

  • New StubMethodBodyTypesTest verifies stub @param callable-string overrides source @param string inside the method body
  • New test also confirms external callers still see stub @return non-empty-string
  • Full analyser + rules test suites pass (7752 tests, 0 failures)

🤖 Generated with Claude Code

adamturcsan and others added 30 commits February 5, 2026 18:02
Difference in days might behave differently when the DateInterval is created from scratch or from a diff.

Filter returned type information for DateInterval::format. It can only be non-falsy for sure
if it's not '%a'.
allows re-use of version-string into PhpVersion parsing
phpstan-bot and others added 26 commits February 18, 2026 12:51
…hpstan#4983)

Co-authored-by: phpstan-bot <79867460+phpstan-bot@users.noreply.github.com>
Co-authored-by: phpstan-bot <ondrej+phpstanbot@mirtes.cz>
Co-authored-by: phpstan-bot <79867460+phpstan-bot@users.noreply.github.com>
Co-authored-by: phpstan-bot <ondrej+phpstanbot@mirtes.cz>
…esolvable (phpstan#4997)

Co-authored-by: phpstan-bot <79867460+phpstan-bot@users.noreply.github.com>
When a PR was created by @phpstan-bot, the changelog would previously
thank the bot. Instead, fetch the PR's reviews via the GitHub API and
thank the people who actually reviewed the PR, excluding the maintainer
and the bot itself. Supports thanking multiple reviewers.

https://claude.ai/code/session_01AAuDLXqrwvhNzwseRW7Wko
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 <noreply@anthropic.com>
@phpstan-bot
Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@mglaman mglaman changed the base branch from 2.2.x to 1.11.x February 20, 2026 15:07
@mglaman
Copy link
Copy Markdown
Contributor Author

mglaman commented Feb 20, 2026

Superseded by #5008 which targets 1.11.x (2.1.x releases) per bot feedback.

@mglaman mglaman closed this Feb 20, 2026
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.

2.1.38 broke stub file in phpstan-drupal for defining callable-string