website/errors/requireImplements.onClass.md
<?php declare(strict_types = 1);
interface HasName
{
public function getName(): string;
}
/**
* @phpstan-require-implements HasName
*/
class MyClass
{
}
The @phpstan-require-implements PHPDoc tag is only valid on traits. It tells PHPStan that any class using the trait must implement the specified interface. Placing this tag on a class or an enum has no effect and indicates a misunderstanding of the tag's purpose.
Move the tag to a trait:
/**
* @phpstan-require-implements HasName
*/
-class MyClass
+trait MyTrait
{
}
Or if the class should implement the interface, use implements directly:
-/**
- * @phpstan-require-implements HasName
- */
-class MyClass
+class MyClass implements HasName
{
+ public function getName(): string
+ {
+ return 'name';
+ }
}