Passed
Pull Request — master (#2)
by Florian
02:12
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
     * @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