AttachCorrelationIdPipelineStep   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B invoke() 0 24 6
A getStageContextClass() 0 4 1
1
<?php
2
namespace PSB\Core\Correlation\Pipeline;
3
4
5
use PSB\Core\HeaderTypeEnum;
6
use PSB\Core\Pipeline\Outgoing\StageContext\OutgoingLogicalMessageContext;
7
use PSB\Core\Pipeline\PipelineStepInterface;
8
9
class AttachCorrelationIdPipelineStep implements PipelineStepInterface
10
{
11
    /**
12
     * @param OutgoingLogicalMessageContext $context
13
     * @param callable                      $next
14
     */
15 3
    public function invoke($context, callable $next)
16
    {
17 3
        $correlationId = null;
18
19 3
        if ($context->getIncomingPhysicalMessage()) {
20 2
            $incomingHeaders = $context->getIncomingPhysicalMessage()->getHeaders();
21
22 2
            if (isset($incomingHeaders[HeaderTypeEnum::CORRELATION_ID])) {
23 1
                $correlationId = $incomingHeaders[HeaderTypeEnum::CORRELATION_ID];
24
            }
25
26 2
            if (!$correlationId && isset($incomingHeaders[HeaderTypeEnum::MESSAGE_ID])) {
27 1
                $correlationId = $incomingHeaders[HeaderTypeEnum::MESSAGE_ID];
28
            }
29
        }
30
31 3
        if (!$correlationId) {
32 1
            $correlationId = $context->getMessageId();
33
        }
34
35 3
        $context->setHeader(HeaderTypeEnum::CORRELATION_ID, $correlationId);
36
37 3
        $next();
38 3
    }
39
40
    /**
41
     * @return string
42
     */
43 1
    public static function getStageContextClass()
44
    {
45 1
        return OutgoingLogicalMessageContext::class;
46
    }
47
}
48