Error Identifier: new.internalEnum
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\CacheDriver;
$driver = new CacheDriver(); // ERROR: Instantiation of internal enum Vendor\Internal\CacheDriver.
Why is it reported? #
An internal enum (or a class typed as an enum marked with @internal) is being instantiated from outside its root namespace. Types marked as @internal are not part of the public API of the package that defines them and are intended to be used only within that package. Instantiating internal types creates a dependency on implementation details that may change without notice in future versions.
How to fix it #
Use the public API provided by the package instead of directly instantiating the internal type:
<?php declare(strict_types = 1);
namespace App;
-use Vendor\Internal\CacheDriver;
+use Vendor\CacheFactory;
-$driver = new CacheDriver();
+$driver = CacheFactory::create();
If no public alternative exists, contact the package maintainer to request a public API for the functionality needed.
How to ignore this error #
You can use the identifier new.internalEnum to ignore this error using a comment:
// @phpstan-ignore new.internalEnum
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: new.internalEnum
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]