Error Identifier: propertyTag.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 Vendor\Internal;
/** @internal */
trait HelperTrait
{
}
<?php declare(strict_types = 1);
namespace App;
use Vendor\Internal\HelperTrait;
/**
* @property HelperTrait $helper // ERROR: PHPDoc tag @property references internal trait HelperTrait.
*/
class Foo
{
}
Why is it reported? #
The @property PHPDoc tag references a trait that has been marked as @internal. Internal traits are implementation details of a package or namespace and are not meant to be used by external code. They may change or be removed without notice in future versions.
Additionally, traits are not valid types in PHP, so using one as a type in a @property tag is problematic regardless of the internal status.
How to fix it #
Replace the internal trait reference in the @property tag with a valid, public type such as an interface or class:
<?php declare(strict_types = 1);
namespace App;
-use Vendor\Internal\HelperTrait;
+use Vendor\HelperInterface;
/**
- * @property HelperTrait $helper
+ * @property HelperInterface $helper
*/
class Foo
{
}
How to ignore this error #
You can use the identifier propertyTag.internalTrait to ignore this error using a comment:
// @phpstan-ignore propertyTag.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: propertyTag.internalTrait
Rules that report this error #
- PHPStan\Rules\InternalTag\RestrictedInternalClassNameUsageExtension [1]