Error Identifier: mixin.internalTrait
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 Some\Internal\HelperTrait;
/**
* @mixin HelperTrait
*/
class Foo // ERROR: PHPDoc tag @mixin references internal trait HelperTrait.
{
}
Why is it reported? #
The @mixin PHPDoc tag references a trait that is marked as @internal. Internal traits are not part of the public API of the package that defines them. Referencing internal types in PHPDoc tags creates a dependency on implementation details that may change without notice in future versions of the package.
How to fix it #
Use a public class or interface provided by the package instead:
<?php declare(strict_types = 1);
namespace App;
-use Some\Internal\HelperTrait;
+use Some\PublicHelper;
/**
- * @mixin HelperTrait
+ * @mixin PublicHelper
*/
class Foo
{
}
If no public alternative exists, remove the @mixin tag and implement the needed methods directly in the class.
How to ignore this error #
You can use the identifier mixin.internalTrait to ignore this error using a comment:
// @phpstan-ignore mixin.internalTrait
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: mixin.internalTrait
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]