Skip to content

Commit e3c062c

Browse files
[Messenger] made dispatch() and handle() return void
1 parent 6542de6 commit e3c062c

26 files changed

+69
-159
lines changed

Asynchronous/Middleware/SendMessageMiddleware.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public function __construct(SenderLocatorInterface $senderLocator, array $messag
3838
*
3939
* {@inheritdoc}
4040
*/
41-
public function handle($envelope, callable $next)
41+
public function handle($envelope, callable $next): void
4242
{
4343
if ($envelope->get(ReceivedStamp::class)) {
4444
// It's a received message. Do not send it back:
45-
return $next($envelope);
45+
$next($envelope);
46+
47+
return;
4648
}
4749

4850
$sender = $this->senderLocator->getSenderForMessage($envelope->getMessage());
@@ -55,7 +57,7 @@ public function handle($envelope, callable $next)
5557
}
5658
}
5759

58-
return $next($envelope);
60+
$next($envelope);
5961
}
6062

6163
private function mustSendAndHandle($message): bool

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* The component is not experimental anymore
88
* All the changes below are BC BREAKS
9+
* `MessageBusInterface::dispatch()` and `MiddlewareInterface::handle()` now return `void`
910
* The signature of `Amqp*` classes changed to take a `Connection` as a first argument and an optional
1011
`Serializer` as a second argument.
1112
* `SenderLocator` has been renamed to `ContainerSenderLocator`

DataCollector/MessengerDataCollector.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ private function collectMessage(string $busName, array $tracedMessage)
9898
'caller' => $tracedMessage['caller'],
9999
);
100100

101-
if (array_key_exists('result', $tracedMessage)) {
102-
$result = $tracedMessage['result'];
103-
$debugRepresentation['result'] = array(
104-
'type' => \is_object($result) ? \get_class($result) : \gettype($result),
105-
'value' => $result,
106-
);
107-
}
108-
109101
if (isset($tracedMessage['exception'])) {
110102
$exception = $tracedMessage['exception'];
111103

Handler/ChainHandler.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ public function __construct(array $handlers)
3939

4040
public function __invoke($message)
4141
{
42-
$results = array();
43-
4442
foreach ($this->handlers as $handler) {
45-
$results[] = $handler($message);
43+
$handler($message);
4644
}
47-
48-
return $results;
4945
}
5046
}

MessageBus.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public function __construct(iterable $middlewareHandlers = array())
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
public function dispatch($message)
41+
public function dispatch($message): void
4242
{
4343
if (!\is_object($message)) {
4444
throw new InvalidArgumentException(sprintf('Invalid type for message argument. Expected object, but got "%s".', \gettype($message)));
4545
}
4646

47-
return \call_user_func($this->callableForNextMiddleware(0, Envelope::wrap($message)), $message);
47+
\call_user_func($this->callableForNextMiddleware(0, Envelope::wrap($message)), $message);
4848
}
4949

5050
private function callableForNextMiddleware(int $index, Envelope $currentEnvelope): callable
@@ -71,7 +71,7 @@ private function callableForNextMiddleware(int $index, Envelope $currentEnvelope
7171
$message = $message->getMessage();
7272
}
7373

74-
return $middleware->handle($message, $this->callableForNextMiddleware($index + 1, $currentEnvelope));
74+
$middleware->handle($message, $this->callableForNextMiddleware($index + 1, $currentEnvelope));
7575
};
7676
}
7777
}

MessageBusInterface.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ interface MessageBusInterface
1919
/**
2020
* Dispatches the given message.
2121
*
22-
* The bus can return a value coming from handlers, but is not required to do so.
23-
*
2422
* @param object|Envelope $message The message or the message pre-wrapped in an envelope
25-
*
26-
* @return mixed
2723
*/
28-
public function dispatch($message);
24+
public function dispatch($message): void;
2925
}

Middleware/AllowNoHandlerMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
*/
1919
class AllowNoHandlerMiddleware implements MiddlewareInterface
2020
{
21-
public function handle($message, callable $next)
21+
public function handle($message, callable $next): void
2222
{
2323
try {
24-
return $next($message);
24+
$next($message);
2525
} catch (NoHandlerForMessageException $e) {
2626
// We allow not having a handler for this message.
2727
}

Middleware/Enhancers/ActivationMiddlewareDecorator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public function __construct(MiddlewareInterface $inner, $activated)
3737
/**
3838
* @param Envelope $envelope
3939
*/
40-
public function handle($envelope, callable $next)
40+
public function handle($envelope, callable $next): void
4141
{
4242
if (\is_callable($this->activated) ? ($this->activated)($envelope) : $this->activated) {
43-
return $this->inner->handle($envelope->getMessageFor($this->inner), $next);
43+
$this->inner->handle($envelope->getMessageFor($this->inner), $next);
44+
} else {
45+
$next($envelope);
4446
}
45-
46-
return $next($envelope);
4747
}
4848
}

Middleware/Enhancers/TraceableMiddleware.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(MiddlewareInterface $inner, Stopwatch $stopwatch, st
3939
/**
4040
* @param Envelope $envelope
4141
*/
42-
public function handle($envelope, callable $next)
42+
public function handle($envelope, callable $next): void
4343
{
4444
$class = \get_class($this->inner);
4545
$eventName = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
@@ -51,19 +51,15 @@ public function handle($envelope, callable $next)
5151
$this->stopwatch->start($eventName, $this->eventCategory);
5252

5353
try {
54-
$result = $this->inner->handle($envelope->getMessageFor($this->inner), function ($message) use ($next, $eventName) {
54+
$this->inner->handle($envelope->getMessageFor($this->inner), function ($message) use ($next, $eventName) {
5555
$this->stopwatch->stop($eventName);
56-
$result = $next($message);
56+
$next($message);
5757
$this->stopwatch->start($eventName, $this->eventCategory);
58-
59-
return $result;
6058
});
6159
} finally {
6260
if ($this->stopwatch->isStarted($eventName)) {
6361
$this->stopwatch->stop($eventName);
6462
}
6563
}
66-
67-
return $result;
6864
}
6965
}

Middleware/HandleMessageMiddleware.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ public function __construct(HandlerLocatorInterface $messageHandlerResolver)
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function handle($message, callable $next)
31+
public function handle($message, callable $next): void
3232
{
3333
$handler = $this->messageHandlerResolver->resolve($message);
34-
$result = $handler($message);
34+
$handler($message);
3535

3636
$next($message);
37-
38-
return $result;
3937
}
4038
}

0 commit comments

Comments
 (0)