@@ -232,20 +232,20 @@ class QueryBus
232232
233233 public function dispatch(object $query): mixed
234234 {
235- return $this->handle($query); // Return type will be inferred
235+ return $this->handle($query); // Return type will be inferred in calling code as query result
236236 }
237237
238238 // Multiple methods per class example
239239 public function execute(object $message): mixed
240240 {
241- return $this->handle($message);
241+ return $this->handle($message); // Return type will be inferred in calling code as query result
242242 }
243243}
244244
245245// Interface-based configuration example
246246interface QueryBusInterface
247247{
248- public function dispatch(object $query): mixed;
248+ public function dispatch(object $query): mixed; // Return type will be inferred in calling code as query result
249249}
250250
251251class QueryBusWithInterface implements QueryBusInterface
@@ -263,12 +263,13 @@ class QueryBusWithInterface implements QueryBusInterface
263263 }
264264}
265265
266- // Usage examples with proper type inference
266+ // Examples of use with proper type inference
267267$query = new GetProductQuery($productId);
268268$queryBus = new QueryBus($messageBus);
269269$queryBusWithInterface = new QueryBusWithInterface($messageBus);
270270
271271$product = $queryBus->dispatch($query); // Returns: Product
272272$product2 = $queryBus->execute($query); // Returns: Product
273273$product3 = $queryBusWithInterface->dispatch($query); // Returns: Product
274+ // Without the feature all above query bus results would be default 'mixed'.
274275` ` `
0 commit comments