Skip to content

Prevent unnecessary method calls on Type - #6076

Merged
staabm merged 1 commit into
phpstan:2.2.xfrom
staabm:prev
Jul 21, 2026
Merged

Prevent unnecessary method calls on Type#6076
staabm merged 1 commit into
phpstan:2.2.xfrom
staabm:prev

Conversation

@staabm

@staabm staabm commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

came here because I saw these methods showing up in profiles of tempest

grafik

$typeWithMethod = $typeWithMethod->filterTypes(static fn (Type $innerType) => $innerType->hasMethod($methodName)->yes());
}

if (!$typeWithMethod->hasMethod($methodName)->yes()) {

@staabm staabm Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before this PR:

in case of a UnionType, this if-condition invoked ->hasMethod($methodName)->yes() again on a UnionType, which previously was filtered with ->filterTypes(static fn (Type $innerType) => $innerType->hasMethod($methodName)->yes()) - so could either contain only types which have the method $methodName, or a NeverType.

@staabm
staabm marked this pull request as ready for review July 21, 2026 10:22
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@staabm
staabm merged commit 8a28718 into phpstan:2.2.x Jul 21, 2026
737 of 742 checks passed
@staabm
staabm deleted the prev branch July 21, 2026 10:42
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.

3 participants