CorrelationIdMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 2
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phauthentic\CorrelationIdBundle\Messenger\Middleware;
6
7
use Phauthentic\CorrelationIdBundle\Messenger\Stamp\CorrelationIdStamp;
8
use Phauthentic\Infrastructure\Utils\CorrelationID;
9
use Symfony\Component\Messenger\Envelope;
10
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
11
use Symfony\Component\Messenger\Middleware\StackInterface;
12
13
/**
14
 *
15
 */
16
class CorrelationIdMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * @SuppressWarnings(PHPMD.StaticAccess)
20
     *
21
     * @throws \Exception
22
     */
23
    public function handle(Envelope $envelope, StackInterface $stack): Envelope
24
    {
25
        if (isset($envelope->all()[CorrelationIdStamp::class])) {
26
            return $stack->next()->handle($envelope, $stack);
27
        }
28
29
        $envelope = $envelope->with(
30
            new CorrelationIdStamp(CorrelationID::toString())
31
        );
32
33
        return $stack->next()->handle($envelope, $stack);
34
    }
35
}
36