Passed
Pull Request — master (#2)
by Florian
02:12
created

CorrelationIdMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 16
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
     * @throws \Exception
20
     */
21
    public function handle(Envelope $envelope, StackInterface $stack): Envelope
22
    {
23
        if (isset($envelope->all()[CorrelationIdStamp::class])) {
24
            return $stack->next()->handle($envelope, $stack);
25
        }
26
27
        $envelope = $envelope->with(
28
            new CorrelationIdStamp(CorrelationID::toString())
29
        );
30
31
        return $stack->next()->handle($envelope, $stack);
32
    }
33
}
34