Passed
Push — master ( cb43db...ab3f16 )
by Florian
48s queued 15s
created

CorrelationIdMiddleware::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 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