Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support 'HasMethodType' on StaticCall #1969

Merged
merged 4 commits into from Nov 5, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 5, 2022

@staabm staabm marked this pull request as ready for review November 5, 2022 10:06
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

if ($objectType->isString()->yes()) {
return new SpecifiedTypes([], []);
if ($objectType->isString()->yes()) {
if ($objectType instanceof ConstantStringType && $objectType->isClassString()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we add isClassString on Type as a followup?

Copy link
Member

Choose a reason for hiding this comment

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

Of course :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already have ConstantStringType->isClassString(): bool,

public function isClassString(): bool
{
if ($this->isClassString) {
return true;
}
$reflectionProvider = ReflectionProviderStaticAccessor::getInstance();
return $reflectionProvider->hasClass($this->value);
}

therefore we need a different name for this new method... any suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

isClassStringType

Copy link
Member

Choose a reason for hiding this comment

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

And make it nicer for 2.0

@ondrejmirtes
Copy link
Member

Yeah, I guess this is usable. Thank you :)

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

We should also test a scenario when a method doesn't exist - for example when we're not in method_exists at all, or when we call a different method than what was asked in method_exists.

@ondrejmirtes ondrejmirtes merged commit 7f6df07 into phpstan:1.9.x Nov 5, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the static-has-method branch November 5, 2022 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants