Skip to content
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

Fix implementsInterface() PHPDoc #277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(array()), 'DateTimeInterface'), false),
array('implementsInterface', array(new ArrayIterator(array()), '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