Error Identifier: selfOut.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);
// In package vendor/some-library:
namespace SomeLibrary;
/** @internal */
enum Status: string
{
case Active = 'active';
case Inactive = 'inactive';
}
<?php declare(strict_types = 1);
// In your code:
namespace App;
use SomeLibrary\Status;
/**
* @template T
*/
class Collection
{
/**
* @phpstan-self-out self<Status>
*/
public function filterByStatus(): void
{
// ...
}
}
Why is it reported? #
The @phpstan-self-out PHPDoc tag references an enum that is marked as @internal. Internal enums are not part of the public API of the package that defines them. Referencing an internal enum in a @phpstan-self-out tag creates a dependency on an implementation detail that may change or be removed without notice.
How to fix it #
Use a public (non-internal) type from the package in the @phpstan-self-out tag instead:
<?php declare(strict_types = 1);
namespace App;
-use SomeLibrary\Status;
+use SomeLibrary\PublicStatus;
/**
* @template T
*/
class Collection
{
/**
- * @phpstan-self-out self<Status>
+ * @phpstan-self-out self<PublicStatus>
*/
public function filterByStatus(): void
{
// ...
}
}
If the enum is internal to the same package, the error will not be reported. The @internal restriction only applies to cross-package usage.
How to ignore this error #
You can use the identifier selfOut.internalEnum to ignore this error using a comment:
// @phpstan-ignore selfOut.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: selfOut.internalEnum
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]