ExceptionThrowingMiddleware::deliver()   A
last analyzed

Complexity

Conditions 1
Paths 0

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 0
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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