IncomingContextFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 91
Duplicated Lines 36.26 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 33
loc 91
ccs 38
cts 38
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A createPhysicalMessageContext() 0 14 1
A createLogicalMessageContext() 16 16 1
A createInvokeHandlerContext() 17 17 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\Pipeline\Incoming;
3
4
5
use PSB\Core\MessageHandlerInterface;
6
use PSB\Core\OutgoingOptionsFactory;
7
use PSB\Core\Pipeline\BusOperations;
8
use PSB\Core\Pipeline\Incoming\StageContext\IncomingLogicalMessageContext;
9
use PSB\Core\Pipeline\Incoming\StageContext\IncomingPhysicalMessageContext;
10
use PSB\Core\Pipeline\Incoming\StageContext\InvokeHandlerContext;
11
use PSB\Core\Pipeline\Incoming\StageContext\TransportReceiveContext;
12
use PSB\Core\Pipeline\PendingTransportOperations;
13
14
class IncomingContextFactory
15
{
16
    /**
17
     * @var BusOperations
18
     */
19
    private $busOperations;
20
21
    /**
22
     * @var OutgoingOptionsFactory
23
     */
24
    private $outgoingOptionsFactory;
25
26
    /**
27
     * @param BusOperations          $busOperations
28
     * @param OutgoingOptionsFactory $outgoingOptionsFactory
29
     */
30 4
    public function __construct(
31
        BusOperations $busOperations,
32
        OutgoingOptionsFactory $outgoingOptionsFactory
33
    ) {
34 4
        $this->busOperations = $busOperations;
35 4
        $this->outgoingOptionsFactory = $outgoingOptionsFactory;
36 4
    }
37
38
    /**
39
     * @param TransportReceiveContext $parentContext
40
     *
41
     * @return IncomingPhysicalMessageContext
42
     */
43 1
    public function createPhysicalMessageContext(TransportReceiveContext $parentContext)
44
    {
45 1
        $physicalMessage = $parentContext->getMessage();
46 1
        return new IncomingPhysicalMessageContext(
47 1
            $physicalMessage,
48 1
            $physicalMessage->getMessageId(),
49 1
            $physicalMessage->getHeaders(),
50 1
            new PendingTransportOperations(),
51 1
            $this->busOperations,
52 1
            $this->outgoingOptionsFactory,
53 1
            $parentContext->getEndpointControlToken(),
54 1
            $parentContext
55
        );
56
    }
57
58
    /**
59
     * @param IncomingLogicalMessage         $logicalMessage
60
     * @param IncomingPhysicalMessageContext $parentContext
61
     *
62
     * @return IncomingLogicalMessageContext
63
     */
64 1 View Code Duplication
    public function createLogicalMessageContext(
65
        IncomingLogicalMessage $logicalMessage,
66
        IncomingPhysicalMessageContext $parentContext
67
    ) {
68 1
        return new IncomingLogicalMessageContext(
69 1
            $logicalMessage,
70 1
            $parentContext->getMessageId(),
71 1
            $parentContext->getHeaders(),
72 1
            $parentContext->getIncomingPhysicalMessage(),
73 1
            $parentContext->getPendingTransportOperations(),
74 1
            $this->busOperations,
75 1
            $this->outgoingOptionsFactory,
76 1
            $parentContext->getEndpointControlToken(),
77 1
            $parentContext
78
        );
79
    }
80
81
    /**
82
     * @param MessageHandlerInterface       $messageHandler
83
     * @param IncomingLogicalMessageContext $parentContext
84
     *
85
     * @return InvokeHandlerContext
86
     */
87 1 View Code Duplication
    public function createInvokeHandlerContext(
88
        MessageHandlerInterface $messageHandler,
89
        IncomingLogicalMessageContext $parentContext
90
    ) {
91 1
        return new InvokeHandlerContext(
92 1
            $messageHandler,
93 1
            $parentContext->getMessage()->getMessageInstance(),
94 1
            $parentContext->getMessageId(),
95 1
            $parentContext->getHeaders(),
96 1
            $parentContext->getIncomingPhysicalMessage(),
97 1
            $parentContext->getPendingTransportOperations(),
98 1
            $this->busOperations,
99 1
            $this->outgoingOptionsFactory,
100 1
            $parentContext->getEndpointControlToken(),
101 1
            $parentContext
102
        );
103
    }
104
}
105