From 2bd8ece47b3f029bf9e6d37c68b924cf2ec3325c 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 db1f3a5..55537f4 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1567,7 +1567,7 @@ public static function interfaceExists($value, $message = '') * @psalm-pure * @psalm-template ExpectedType of object * @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 5670e2a..3561e1c 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4075,7 +4075,7 @@ public static function allNullOrInterfaceExists($value, $message = '') * @psalm-pure * @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 @@ -4094,7 +4094,7 @@ public static function nullOrImplementsInterface($value, $interface, $message = * @psalm-pure * @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 @@ -4117,7 +4117,7 @@ public static function allImplementsInterface($value, $interface, $message = '') * @psalm-pure * @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 567fddf..ebedc02 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -13,6 +13,7 @@ use ArrayIterator; use ArrayObject; +use DateTimeImmutable; use Error; use Exception; use LogicException; @@ -445,6 +446,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 {