Skip to content

improve is_subclass_of type checks#1321

Merged
ondrejmirtes merged 12 commits intophpstan:1.7.xfrom
staabm:subclass-strings
May 17, 2022
Merged

improve is_subclass_of type checks#1321
ondrejmirtes merged 12 commits intophpstan:1.7.xfrom
staabm:subclass-strings

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented May 16, 2022


/**
* @param ($allow_string is false ? object : object|string) $object_or_class
* @param class-string $class
Copy link
Contributor Author

@staabm staabm May 16, 2022

Choose a reason for hiding this comment

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

changed both, is_a and is_subclass_of $class arg back to string for max compat with 1.6.x

$allowString = !$allowStringType->equals(new ConstantBooleanType(false));

// prevent false-positives in IsAFunctionTypeSpecifyingHelper
if ($objectOrClassType instanceof GenericClassStringType && $classType instanceof GenericClassStringType) {
Copy link
Contributor Author

@staabm staabm May 16, 2022

Choose a reason for hiding this comment

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

obviously this is not a great fix, but with this PR we fix the existing/reported false-positives.
proper support for generic-class-string in is_subclass_of could be added later.. since there are not existing tests for this case, this should be fine for now

@staabm staabm marked this pull request as ready for review May 16, 2022 19:35
@ondrejmirtes ondrejmirtes merged commit f52dc41 into phpstan:1.7.x May 17, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the subclass-strings branch May 17, 2022 07:49
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-positive with is_subclass_of

3 participants