Error Identifier: requireExtends.internalClass
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);
namespace App;
use Vendor\Internal\BaseClass;
/**
* @phpstan-require-extends BaseClass
*/
interface MyInterface
{
}
Where BaseClass is marked as @internal in the Vendor package.
Why is it reported? #
The @phpstan-require-extends PHPDoc tag references a class that is marked as @internal. Internal classes are not meant to be used outside the package that defines them. Referencing an internal class in a require-extends constraint creates a dependency on an implementation detail that may change without notice.
How to fix it #
Use a public (non-internal) class from the package instead.
/**
- * @phpstan-require-extends BaseClass
+ * @phpstan-require-extends PublicBaseClass
*/
interface MyInterface
{
}
If no public alternative exists, consider whether the constraint is necessary, or contact the package maintainer to request a public API.
How to ignore this error #
You can use the identifier requireExtends.internalClass to ignore this error using a comment:
// @phpstan-ignore requireExtends.internalClass
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: requireExtends.internalClass
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]