@@ -221,20 +221,20 @@ class QueryBus
221221
222222 public function dispatch(object $query): mixed
223223 {
224- return $this->handle($query); // Return type will be inferred
224+ return $this->handle($query); // Return type will be inferred in calling code as query result
225225 }
226226
227227 // Multiple methods per class example
228228 public function execute(object $message): mixed
229229 {
230- return $this->handle($message);
230+ return $this->handle($message); // Return type will be inferred in calling code as query result
231231 }
232232}
233233
234234// Interface-based configuration example
235235interface QueryBusInterface
236236{
237- public function dispatch(object $query): mixed;
237+ public function dispatch(object $query): mixed; // Return type will be inferred in calling code as query result
238238}
239239
240240class QueryBusWithInterface implements QueryBusInterface
@@ -252,12 +252,13 @@ class QueryBusWithInterface implements QueryBusInterface
252252 }
253253}
254254
255- // Usage examples with proper type inference
255+ // Examples of use with proper type inference
256256$query = new GetProductQuery($productId);
257257$queryBus = new QueryBus($messageBus);
258258$queryBusWithInterface = new QueryBusWithInterface($messageBus);
259259
260260$product = $queryBus->dispatch($query); // Returns: Product
261261$product2 = $queryBus->execute($query); // Returns: Product
262262$product3 = $queryBusWithInterface->dispatch($query); // Returns: Product
263+ // Without the feature all above query bus results would be default 'mixed'.
263264` ` `
0 commit comments