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

Fix ImpossibleCheckTypeFunctionCallRule for is_subclass_of and is_a #3404

Open
wants to merge 7 commits into
base: 1.12.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
Contributor

Closes phpstan/phpstan#3979
which can be simplified to https://phpstan.org/r/ef72a996-8fbe-4a4e-831f-4d78c542ad19

I'm not sure there is a better (easy ?) fix for this issue. is_subclass_of($string, $bar) specify the type of $string to class-string when true, but it doesn't mean that the call is useless if the param is already a class-string.

I discovered there was an exclusion of is_a in the ImpossibleCheckTypeFunctionCallRule (maybe for the same reason)
so I think it could be the same for is_subclass_of since the behavior is similar.

@ondrejmirtes
Copy link
Member

Changing the rule is not going to help you against "Result of && is always false.".

I'd much rather change the logic in IsSubclassOfFunctionTypeSpecifyingExtension.

@VincentLanglet VincentLanglet changed the title Disable ImpossibleCheckTypeFunctionCallRule for is_subclass_of Fix ImpossibleCheckTypeFunctionCallRule for is_subclass_of and is_a Sep 5, 2024
@@ -1133,9 +1133,7 @@ public function dataCondition(): iterable
new Arg(new Variable('stringOrNull')),
new Arg(new Expr\ConstFetch(new Name('false'))),
]),
[
'$object' => 'object',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (is_subclass_of($object, $stringOrNull, false))

specified $object as object but this was already known so it's not a big loss.

@VincentLanglet VincentLanglet marked this pull request as ready for review September 6, 2024 09:35
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@VincentLanglet
Copy link
Contributor Author

I'd much rather change the logic in IsSubclassOfFunctionTypeSpecifyingExtension.

I think it was possible indeed, I get something working.

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