Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brandonkelly opened this issue Sep 19, 2023 · 6 comments

Comments

@brandonkelly
Copy link

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!

@ondrejmirtes
Copy link
Member

This could be paired with annotations similar to @psalm-require-extends and @psalm-require-implements: https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-require-extends

@brandonkelly
Copy link
Author

Those would be great as well!

@staabm
Copy link
Contributor

staabm commented Jan 5, 2024

@brandonkelly @ben-challis or anyone else in need of require-use:

Recently I started implementing require-extends and require-implements phpdocs into phpstan.

Afterwards I can make require-use a priority, in case we find sponsors for it.

@ondrejmirtes
Copy link
Member

I don't think that require-use is actually a good idea because we can't rely on the method signatures to stay the same. I think that require-extends and require-implements will be sufficient.

@brandonkelly
Copy link
Author

@require-extends is perfect. I’ll go ahead and close this.

Copy link

github-actions bot commented Feb 9, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants