Skip to content

support 'HasMethodType' on StaticCall #1969

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

Merged
merged 4 commits into from
Nov 5, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 5, 2022

@staabm staabm force-pushed the static-has-method branch from 2fee0d2 to 2302a61 Compare November 5, 2022 09:44
@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.

@staabm staabm force-pushed the static-has-method branch from 94d479a to 4e8c9d6 Compare November 5, 2022 11:12
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.

@staabm staabm force-pushed the static-has-method branch from 51ae84d to 95dba26 Compare November 5, 2022 13:29
@staabm staabm force-pushed the static-has-method branch from 95dba26 to 9d1bca9 Compare November 5, 2022 13:32
@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
Development

Successfully merging this pull request may close these issues.

False positives when using method_exists() with a static method
3 participants