phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Fix ImpossibleCheckTypeFunctionCallRule for `is_subclass_of` and `is_a`

Open VincentLanglet opened this issue 1 year ago • 3 comments

Closes https://github.com/phpstan/phpstan/issues/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.

VincentLanglet avatar Sep 05 '24 17:09 VincentLanglet

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

I'd much rather change the logic in IsSubclassOfFunctionTypeSpecifyingExtension.

ondrejmirtes avatar Sep 05 '24 19:09 ondrejmirtes

This pull request has been marked as ready for review.

phpstan-bot avatar Sep 06 '24 09:09 phpstan-bot

I'd much rather change the logic in IsSubclassOfFunctionTypeSpecifyingExtension.

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

VincentLanglet avatar Sep 06 '24 09:09 VincentLanglet

Friendly ping @ondrejmirtes ; this PR is ready to be re-reviewed :)

VincentLanglet avatar Nov 06 '24 19:11 VincentLanglet

Thank you.

ondrejmirtes avatar Jan 11 '25 12:01 ondrejmirtes

Unfortunately I have to revert this. it leads to false positives like: https://phpstan.org/r/5941cd95-26d7-49cf-a2e0-ffc21c4a7697

ondrejmirtes avatar Jan 19 '25 15:01 ondrejmirtes

Unfortunately I have to revert this. it leads to false positives like: phpstan.org/r/5941cd95-26d7-49cf-a2e0-ffc21c4a7697

No problem, I'll try to improve the idea in https://github.com/phpstan/phpstan-src/pull/3788 Did you had another false positive I have to add as non-regression test ?

VincentLanglet avatar Jan 19 '25 17:01 VincentLanglet