Support for Symfony HandleTrait
I think it would be great if the extension could automatically recognize the type of HandleTrait of symfony.
The given message to the handle trait example:
$this->handle(new CreateUserMessage());
does only have 1 Handler which return type the return type of the handle trait will be. Example:
class CreateUserMessageHandler {
public function __invoke(CreateUserMessage $message): User
{
return new User($message->getUserName());
}
}
The bin/console debug:messenger already shows the mapping between Message and Handlers.
The HandleStamp contains under the getResult method the result of every handler: https://github.com/symfony/symfony/blob/8eed84bb2df613101949ca2e786ac383d2f349fd/src/Symfony/Component/Messenger/HandleTrait.php#L45. The HandleTrait only allows one handler per message, that make the result recognize able. Not sure if its even possible to overwrite the result of a trait. Sadly my skillset for providing this myself is to low, but would think it would be a great feature.
Currenty workaround is:
/** @var User */
$user = $this->handle(new CreateUserMessage());
The first parameter of console.command.messenger_debug service would contain the mapping between message and handler so we can guess the type from there.
Did anybody take a look on that so far to give some insights? Today, I'm going to start working on this.
So far, I researched that in current version not having of this feature request, it could be a blocker.
but I'm keep digging :wink:
I'm happy to announce that PR for that is done and ready for review here :)
Feel free to review and give your feedback, thank you :)
There's also another QueryBus-classes related topic which I wanted to cover with reusing this feature. It's described in this comment. If you have idea how to solve it, please share it here :) Thanks, again
Implemented https://github.com/phpstan/phpstan-symfony/pull/404
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.