Skip to content

@phpstan-require-use for requiring implementors/subclasses to use certain traits #9899

@brandonkelly

Description

@brandonkelly

Feature request

Interfaces and abstract classes should be able to specify a @phpstan-require-use tag, which tells PHPStan that implementors and subclasses are expected to use a specified trait.

For example, yii\db\QueryInterface in Yii 2 expects that implementors will use yii\db\QueryTrait.

We’ve followed that convention in Craft CMS, e.g. with craft\base\FieldInterface + craft\base\FieldTrait.

With this convention, it’s not currently possible to make PHPStan happy when targeting PHP 8.2. (Prior PHP versions were only passable thanks to PHPStan assuming that trait-defined properties were actually just dynamic properties.)

Did PHPStan help you today? Did it make you happy in any way?

It was a huge help ensuring our unit tests looked good as we were upgrading to Codeception 5!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions