OutgoingPhysicalMessageMutationPipelineStep   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 56
loc 56
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A invoke() 26 26 3
A getStageContextClass() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace PSB\Core\MessageMutation\Pipeline\Outgoing;
3
4
5
use PSB\Core\MessageMutatorRegistry;
6
use PSB\Core\Pipeline\Outgoing\StageContext\OutgoingPhysicalMessageContext;
7
use PSB\Core\Pipeline\PipelineStepInterface;
8
9 View Code Duplication
class OutgoingPhysicalMessageMutationPipelineStep implements PipelineStepInterface
10
{
11
    /**
12
     * @var MessageMutatorRegistry
13
     */
14
    private $mutatorRegistry;
15
16
    /**
17
     * IncomingPhysicalMessageMutationPipelineStep constructor.
18
     *
19
     * @param MessageMutatorRegistry $mutatorRegistry
20
     */
21 4
    public function __construct(MessageMutatorRegistry $mutatorRegistry)
22
    {
23 4
        $this->mutatorRegistry = $mutatorRegistry;
24 4
    }
25
26
    /**
27
     * @param OutgoingPhysicalMessageContext $context
28
     * @param callable                       $next
29
     */
30 2
    public function invoke($context, callable $next)
31
    {
32 2
        $mutatorIds = $this->mutatorRegistry->getOutgoingPhysicalMessageMutatorIds();
33
34 2
        if (empty($mutatorIds)) {
35 1
            $next();
36 1
            return;
37
        }
38
39 1
        $physicalMessage = $context->getMessage();
40 1
        $mutatorContext = new OutgoingPhysicalMessageMutationContext(
41 1
            $physicalMessage->getBody(),
42 1
            $physicalMessage->getHeaders()
43
        );
44
45 1
        foreach ($mutatorIds as $mutatorId) {
46
            /** @var OutgoingPhysicalMessageMutatorInterface $mutator */
47 1
            $mutator = $context->getBuilder()->build($mutatorId);
48 1
            $mutator->mutateOutgoing($mutatorContext);
49
        }
50
51 1
        $physicalMessage->replaceBody($mutatorContext->getBody());
52 1
        $physicalMessage->replaceHeaders($mutatorContext->getHeaders());
53
54 1
        $next();
55 1
    }
56
57
    /**
58
     * @return string
59
     */
60 1
    public static function getStageContextClass()
61
    {
62 1
        return OutgoingPhysicalMessageContext::class;
63
    }
64
}
65