Skip to content

Commit

Permalink
Fix implementsInterface() PHPDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Oct 17, 2024
1 parent 306905c commit 98b343c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ public static function interfaceExists($value, $message = '')
*
* @psalm-param class-string<ExpectedType> $interface
*
* @psalm-assert class-string<ExpectedType> $value
* @psalm-assert class-string<ExpectedType>|ExpectedType $value
*
* @param mixed $value
* @param mixed $interface
Expand Down
6 changes: 3 additions & 3 deletions src/Mixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4167,7 +4167,7 @@ public static function allNullOrInterfaceExists($value, $message = '')
*
* @psalm-template ExpectedType of object
* @psalm-param class-string<ExpectedType> $interface
* @psalm-assert class-string<ExpectedType>|null $value
* @psalm-assert class-string<ExpectedType>|ExpectedType|null $value
*
* @param mixed $value
* @param mixed $interface
Expand All @@ -4187,7 +4187,7 @@ public static function nullOrImplementsInterface($value, $interface, $message =
*
* @psalm-template ExpectedType of object
* @psalm-param class-string<ExpectedType> $interface
* @psalm-assert iterable<class-string<ExpectedType>> $value
* @psalm-assert iterable<class-string<ExpectedType>|ExpectedType> $value
*
* @param mixed $value
* @param mixed $interface
Expand All @@ -4211,7 +4211,7 @@ public static function allImplementsInterface($value, $interface, $message = '')
*
* @psalm-template ExpectedType of object
* @psalm-param class-string<ExpectedType> $interface
* @psalm-assert iterable<class-string<ExpectedType>|null> $value
* @psalm-assert iterable<class-string<ExpectedType>|ExpectedType|null> $value
*
* @param mixed $value
* @param mixed $interface
Expand Down
5 changes: 5 additions & 0 deletions tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ArrayIterator;
use ArrayObject;
use DateTime;
use DateTimeImmutable;
use Error;
use Exception;
use LogicException;
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 6 additions & 6 deletions tests/static-analysis/assert-implementsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*
* @param mixed $value
*
* @return class-string<Serializable>
* @return Serializable|class-string<Serializable>
*/
function implementsInterface($value): string
function implementsInterface($value)
{
Assert::implementsInterface($value, Serializable::class);

Expand All @@ -24,9 +24,9 @@ function implementsInterface($value): string
*
* @param mixed $value
*
* @return null|class-string<Serializable>
* @return Serializable|class-string<Serializable>|null
*/
function nullOrImplementsInterface($value): ?string
function nullOrImplementsInterface($value)
{
Assert::nullOrImplementsInterface($value, Serializable::class);

Expand All @@ -38,7 +38,7 @@ function nullOrImplementsInterface($value): ?string
*
* @param mixed $value
*
* @return iterable<class-string<Serializable>>
* @return iterable<mixed, Serializable|class-string<Serializable>>
*/
function allImplementsInterface($value): iterable
{
Expand All @@ -52,7 +52,7 @@ function allImplementsInterface($value): iterable
*
* @param mixed $value
*
* @return iterable<class-string<Serializable>|null>
* @return iterable<mixed, Serializable|class-string<Serializable>|null>
*/
function allNullOrImplementsInterface($value): iterable
{
Expand Down

0 comments on commit 98b343c

Please sign in to comment.