phpstan-symfony icon indicating copy to clipboard operation
phpstan-symfony copied to clipboard

using messenger HandleTrait as QueryBus with appropriate result typing

Open bnowak opened this issue 10 months ago • 5 comments

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.

bnowak avatar Jan 17 '25 12:01 bnowak

@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 ?

michaljusiega avatar Feb 27 '25 11:02 michaljusiega

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.

bnowak avatar Mar 14 '25 13:03 bnowak

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 avatar May 05 '25 15:05 ondrejmirtes

@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:

bnowak avatar Jul 28 '25 07:07 bnowak

@ondrejmirtes any chances to review & merge it soon, please? :)

bnowak avatar Aug 29 '25 07:08 bnowak