Skip to content

Commit 53cecc4

Browse files
[Messenger] made dispatch() and handle() return void
1 parent dd432c4 commit 53cecc4

27 files changed

+71
-163
lines changed

src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(ManagerRegistry $managerRegistry, ?string $entityMan
3131
$this->entityManagerName = $entityManagerName;
3232
}
3333

34-
public function handle($message, callable $next)
34+
public function handle($message, callable $next): void
3535
{
3636
$entityManager = $this->managerRegistry->getManager($this->entityManagerName);
3737

@@ -41,15 +41,13 @@ public function handle($message, callable $next)
4141

4242
$entityManager->getConnection()->beginTransaction();
4343
try {
44-
$result = $next($message);
44+
$next($message);
4545
$entityManager->flush();
4646
$entityManager->getConnection()->commit();
4747
} catch (\Throwable $exception) {
4848
$entityManager->getConnection()->rollBack();
4949

5050
throw $exception;
5151
}
52-
53-
return $result;
5452
}
5553
}

src/Symfony/Component/Messenger/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(ReceivedMessage::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

src/Symfony/Component/Messenger/CHANGELOG.md

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

77
* The component is not experimental anymore
8+
* [BC BREAK] `MessageBusInterface::dispatch()` and `MiddlewareInterface::handle()` now return `void`
89
* [BC BREAK] The signature of `Amqp*` classes changed to take a `Connection` as a first argument and an optional
910
`Serializer` as a second argument.
1011
* [BC BREAK] `SenderLocator` has been renamed to `ContainerSenderLocator`

src/Symfony/Component/Messenger/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

src/Symfony/Component/Messenger/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
}

src/Symfony/Component/Messenger/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
}

src/Symfony/Component/Messenger/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
}

src/Symfony/Component/Messenger/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
}

src/Symfony/Component/Messenger/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
}

src/Symfony/Component/Messenger/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
}

0 commit comments

Comments
 (0)