-
Notifications
You must be signed in to change notification settings - Fork 27
Assert::implementsInterface($foo, <Type>)
is incorrectly being translated to assert($foo instanceof <Type>)
#18
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
Comments
Can you tell me some real-world examples of implementsInterface usages? I've seen examples where both arguments are literal strings which doesn't seem very useful. |
Currently finding it in something like: class MyThingFactory
{
public function make(string $thing)
{
Assert::implementsInterface($thing, SomeDto::class);
// use $thing static API here
}
} |
Note that this is completely removable if I use something like: class MyThingFactory
{
/**
* @template T of SomeDto
* @param class-string<T> $thing
*/
public function make(string $thing)
{
Assert::implementsInterface($thing, SomeDto::class);
// use $thing static API here
}
} Not sure if that's understood by the tooling yet though |
This leads to weird hacks in real projects: |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Assert::implementsInterface()
works onobject|string
, not justobject
, so it should be translated to something likeassert($foo instanceof $type || in_array($interface, \class_implements($value)))
(see https://3v4l.org/VdIbR).Not sure what the correct translation (understood by PHPStan) would be.
For reference, this is the current implementation:
phpstan-webmozart-assert/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Lines 303 to 313 in 97cde39
The text was updated successfully, but these errors were encountered: