ExceptionThrowingMiddleware   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A deliver() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Werkspot\MessageBus\Bus\DeliveryChain\Middleware;
6
7
use Werkspot\MessageBus\Bus\DeliveryChain\Middleware\Exception\MessageShouldHaveBeenDeliveredException;
8
use Werkspot\MessageBus\Bus\DeliveryChain\MiddlewareInterface;
9
use Werkspot\MessageBus\Message\MessageInterface;
10
11
/**
12
 * This middleware can be used to make sure every message we deliver is handled by a handler.
13
 *
14
 * During development I had a bug in the Async handler that would do some check on the message it got and skip it if
15
 * the deliver_at was in the past.
16
 *
17
 * So in the QueuedCommand table I put the deliver_at at now(), but then the async handler would skip it, and not
18
 * a single execution middleware would handle it. So without any error it was removed from the queue and never delivered.
19
 * This is obviously a very big problem.
20
 *
21
 * To prevent it I put this middleware at the end of the chain to prevent this.
22
 *
23
 * It's a bit defensive, but it's better then having messages not delivered without any log/error :(
24
 */
25
final class ExceptionThrowingMiddleware implements MiddlewareInterface
26
{
27 1
    public function deliver(MessageInterface $message, callable $next): void
28
    {
29 1
        throw new MessageShouldHaveBeenDeliveredException();
30
    }
31
}
32