webmozarts / assert

Assertions to validate method input/output with nice error messages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow multiple values for instanceof

theofidry opened this issue · comments

As of now we have:

public static function isInstanceOf($value, $class, $message = '')

It would however be convenient to be able to do:

Assert::isInstanceOf($object, [Foo::class, Bar::class]);

instead of:

Assert::true($object instanceof Foo || $object instanceof Bar);

or another alternative

I didn't check the commits history to confirm if the issue is older or newer, but I can see that this method is already implemented as part of the Assert class:

public static function isInstanceOfAny($value, array $classes, $message = '')

Please check it here:
https://github.com/webmozart/assert/blob/master/src/Assert.php#L393-L406

So I guess that this is requesting something that already exists, and the issue can be closed?

Oh indeed, thanks!

Good to know this is what you need 😄