phpstan-symfony
phpstan-symfony copied to clipboard
using messenger HandleTrait as QueryBus with appropriate result typing
This PR goal is to determine correct result typing for QueryBus kind of classes which uses SF messenger HandleTrait internally and simply return its results.
@ondrejmirtes Sorry to disturb you, but I think this is one of the pieces that is missing in this whole puzzle to support. Can we move forward ?
Hi @michaljusiega, thanks for your reply. I think we can add it - no problem. However, from my perspective it's more important to address the root issue (missing feature) of the topic (described here). My reasoning is without having this result interpreted on bus class level - this is much less useful in general.
So this QueryBus class is something in your codebase and you want the same type inference that classes using HandleTrait and calling the handle method have?
You can simply write a dynamic return type extension for QueryBus::dispatch() that delegates the type resolution to new MethodCall($methodCall->var, 'handle', $methodCall->getArgs()).
@ondrejmirtes It's ready for review now. You were right about my intentions, however I wanted to make it working for any class that uses HandleTrait internally. I didn't want to hardcoded it, so made it parameterized. I've added also support for interfaces. Please review in you free time :pray:
It's likely to be conflicted with my another PR about splitting tests, so once first of these PR will be merged I can resolve conflicts on another one. :wink:
@ondrejmirtes any chances to review & merge it soon, please? :)