From 98b343cdb4628c02f6edc0c4e4bddcdd12f0223e Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Wed, 5 Oct 2022 14:18:33 +0200 Subject: [PATCH] Fix `implementsInterface()` PHPDoc --- src/Assert.php | 2 +- src/Mixin.php | 6 +++--- tests/AssertTest.php | 5 +++++ tests/static-analysis/assert-implementsInterface.php | 12 ++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index 7058112..235fd5c 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1609,7 +1609,7 @@ public static function interfaceExists($value, $message = '') * * @psalm-param class-string $interface * - * @psalm-assert class-string $value + * @psalm-assert class-string|ExpectedType $value * * @param mixed $value * @param mixed $interface diff --git a/src/Mixin.php b/src/Mixin.php index ae958ce..fad0d47 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4167,7 +4167,7 @@ public static function allNullOrInterfaceExists($value, $message = '') * * @psalm-template ExpectedType of object * @psalm-param class-string $interface - * @psalm-assert class-string|null $value + * @psalm-assert class-string|ExpectedType|null $value * * @param mixed $value * @param mixed $interface @@ -4187,7 +4187,7 @@ public static function nullOrImplementsInterface($value, $interface, $message = * * @psalm-template ExpectedType of object * @psalm-param class-string $interface - * @psalm-assert iterable> $value + * @psalm-assert iterable|ExpectedType> $value * * @param mixed $value * @param mixed $interface @@ -4211,7 +4211,7 @@ public static function allImplementsInterface($value, $interface, $message = '') * * @psalm-template ExpectedType of object * @psalm-param class-string $interface - * @psalm-assert iterable|null> $value + * @psalm-assert iterable|ExpectedType|null> $value * * @param mixed $value * @param mixed $interface diff --git a/tests/AssertTest.php b/tests/AssertTest.php index b95eba1..52e2141 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -14,6 +14,7 @@ use ArrayIterator; use ArrayObject; use DateTime; +use DateTimeImmutable; use Error; use Exception; use LogicException; @@ -447,6 +448,10 @@ public function getTests() array('interfaceExists', array(__CLASS__), false), array('implementsInterface', array('ArrayIterator', 'Traversable'), true), array('implementsInterface', array(__CLASS__, 'Traversable'), false), + array('implementsInterface', array(new DateTimeImmutable(), 'DateTimeInterface'), true), + array('implementsInterface', array(new DateTimeImmutable(), 'Traversable'), false), + array('implementsInterface', array(new ArrayIterator([]), 'DateTimeInterface'), false), + array('implementsInterface', array(new ArrayIterator([]), 'Traversable'), true), array('propertyExists', array((object) array('property' => 0), 'property'), true), array('propertyExists', array((object) array('property' => null), 'property'), true), array('propertyExists', array((object) array('property' => null), 'foo'), false), diff --git a/tests/static-analysis/assert-implementsInterface.php b/tests/static-analysis/assert-implementsInterface.php index 7080520..9ac1da8 100644 --- a/tests/static-analysis/assert-implementsInterface.php +++ b/tests/static-analysis/assert-implementsInterface.php @@ -10,9 +10,9 @@ * * @param mixed $value * - * @return class-string + * @return Serializable|class-string */ -function implementsInterface($value): string +function implementsInterface($value) { Assert::implementsInterface($value, Serializable::class); @@ -24,9 +24,9 @@ function implementsInterface($value): string * * @param mixed $value * - * @return null|class-string + * @return Serializable|class-string|null */ -function nullOrImplementsInterface($value): ?string +function nullOrImplementsInterface($value) { Assert::nullOrImplementsInterface($value, Serializable::class); @@ -38,7 +38,7 @@ function nullOrImplementsInterface($value): ?string * * @param mixed $value * - * @return iterable> + * @return iterable> */ function allImplementsInterface($value): iterable { @@ -52,7 +52,7 @@ function allImplementsInterface($value): iterable * * @param mixed $value * - * @return iterable|null> + * @return iterable|null> */ function allNullOrImplementsInterface($value): iterable {