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

Allow to Assert::isInstanceOf() to work with generic and anonymous class strings #184

Open
wants to merge 1 commit into
base: 1.2.x
Choose a base branch
from

Conversation

axlon
Copy link

@axlon axlon commented Jul 4, 2024

This should fix #183 by adding extra checks for class strings to the type resolvers for Assert::isInstanceOf(). Before this PR the extension would do nothing if it couldn't find a constant class name, now it will always narrow to at least object

@axlon axlon force-pushed the fix-issue-183 branch 2 times, most recently from 1b44114 to cee8dd4 Compare July 4, 2024 21:38

Assert::isInstanceOfAny($f, [17, self::class]);
assertType('PHPStan\Type\WebMozartAssert\TypeTest', $f);
assertType('object', $f);
Copy link
Author

Choose a reason for hiding this comment

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

This is the only type that seems to have gotten less specific, this is because we now always fall back to object when we can't find any class names, so we end up with object|PHPStan\Type\WebMozartAssert\TypeTest which is then further normalized to object.

I don't know how big of a deal this is as this code would fail in runtime (17 not being a valid class name)

@axlon axlon requested a review from ondrejmirtes July 4, 2024 21:42
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.

Assert::isInstanceOf*() does not work with generics
2 participants