phpstan-webmozart-assert icon indicating copy to clipboard operation
phpstan-webmozart-assert copied to clipboard

Add FQCN support in Assert::implementsInterface

Open karser opened this issue 5 years ago • 1 comments

The function implementsInterface($value, $interface, $message = '') from the docs

Check that a class implements an interface.

Here is the code:

<?php declare(strict_types=1);

namespace App;

use DateTimeInterface;
use Webmozart\Assert\Assert;

Assert::implementsInterface(\DateTime::class, DateTimeInterface::class);
Assert::implementsInterface(\DateTimeZone::class, DateTimeInterface::class);

Here is phpstan error:

Call to static method Webmozart\Assert\Assert::implementsInterface() with 'DateTime' and 'DateTimeInterface' will always evaluate to false.      
Call to static method Webmozart\Assert\Assert::implementsInterface() with 'DateTimeZone' and 'DateTimeInterface' will always evaluate to false.  

karser avatar Oct 21 '19 16:10 karser

The error is not with the FQN, the problem is that the phpstan implementation is interpreting the first parameter as an object and checks if implements the interface and comes to the conclusion that the string "DateTime" never implements a DateTimeInterface. This should be fixed by #16 .

mamazu avatar Oct 31 '19 10:10 mamazu

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Nov 06 '22 00:11 github-actions[bot]