phpstan / phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!
https://phpstan.org/
MIT License
13.03k stars 891 forks source link

Support concept of "decorated" mixins #11673

Open calebdw opened 2 months ago

calebdw commented 2 months ago

Feature request

Hello!

Please see https://github.com/larastan/larastan/issues/2034 for some context. Essentially this idea of a "decorated" mixin (where the original called on type is returned instead of the return type from the mixin method) is fairly common---it would be nice to have support for this without having to create a custom DynamicReturnTypeExtension / ClassReflectionExtension. Maybe something like:

Note that the Laravel framework also has the same idea of a "decorated" forwarded call where the called on type is returned if the mixin object returns itself (otherwise it returns the method return type).

Thanks!

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

Yes! This gives me confidence that my code is safe to ship :)

ondrejmirtes commented 2 months ago

Hey, @mixin is also just another Class Reflection extension so if you need a different behaviour, you can create your own.

I don't think this is as common as you think, outside of Laravel.