website/errors/requireExtends.trait.md
<?php declare(strict_types = 1);
trait Logging
{
}
/**
* @phpstan-require-extends Logging
*/
interface HasLogging
{
}
The @phpstan-require-extends PHPDoc tag references a trait, but it expects a class. A class can only extend another class, not a trait. Traits are used via the use keyword, not through inheritance.
If you want to require that a class uses a specific trait, there is no built-in PHPDoc tag for that. Instead, reference a class in @phpstan-require-extends:
<?php declare(strict_types = 1);
+class BaseWithLogging
+{
+ use Logging;
+}
+
/**
- * @phpstan-require-extends Logging
+ * @phpstan-require-extends BaseWithLogging
*/
interface HasLogging
{
}
Alternatively, if the trait should be an interface, use @phpstan-require-implements instead:
<?php declare(strict_types = 1);
-trait Logging
+interface Logging
{
}
/**
- * @phpstan-require-extends Logging
+ * @phpstan-require-implements Logging
*/
interface HasLogging
{
}