Error Identifier: requireImplements.onInterface
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
interface HasName
{
}
/**
* @phpstan-require-implements HasName
*/
interface Nameable
{
}
Why is it reported? #
The @phpstan-require-implements PHPDoc tag is only valid on traits. It restricts which classes can use a trait by requiring them to implement a specific interface. Using this tag on an interface or a class has no meaning and is not supported by PHPStan.
How to fix it #
If the intent is to constrain trait usage, move the tag to a trait:
<?php declare(strict_types = 1);
interface HasName
{
}
-/**
- * @phpstan-require-implements HasName
- */
-interface Nameable
-{
-}
+/**
+ * @phpstan-require-implements HasName
+ */
+trait Nameable
+{
+}
If the intent is to make one interface extend another, use standard interface inheritance:
<?php declare(strict_types = 1);
interface HasName
{
}
-/**
- * @phpstan-require-implements HasName
- */
-interface Nameable
-{
-}
+interface Nameable extends HasName
+{
+}
How to ignore this error #
You can use the identifier requireImplements.onInterface to ignore this error using a comment:
// @phpstan-ignore requireImplements.onInterface
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: requireImplements.onInterface
Rules that report this error #
- PHPStan\Rules\PhpDoc\RequireImplementsDefinitionClassRule [1]