RabbitMqTransportInfrastructure   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 54.55%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 12
dl 0
loc 110
ccs 18
cts 33
cp 0.5455
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A configureSendInfrastructure() 0 10 1
A configureReceiveInfrastructure() 0 18 1
A configureSubscriptionInfrastructure() 0 12 1
A toTransportAddress() 0 4 1
A getLocalAddress() 0 4 1
1
<?php
2
namespace PSB\Core\Transport\RabbitMq\Config;
3
4
5
use PSB\Core\KnownSettingsEnum;
6
use PSB\Core\Transport\Config\TransportInfrastructure;
7
use PSB\Core\Transport\Config\TransportReceiveInfrastructure;
8
use PSB\Core\Transport\Config\TransportSendInfrastructure;
9
use PSB\Core\Transport\Config\TransportSubscriptionInfrastructure;
10
use PSB\Core\Transport\RabbitMq\BrokerModel;
11
use PSB\Core\Transport\RabbitMq\MessageConverter;
12
use PSB\Core\Transport\RabbitMq\MessageProcessor;
13
use PSB\Core\Transport\RabbitMq\RabbitMqMessageDispatcher;
14
use PSB\Core\Transport\RabbitMq\RabbitMqMessagePusher;
15
use PSB\Core\Transport\RabbitMq\RabbitMqQueueCreator;
16
use PSB\Core\Transport\RabbitMq\RabbitMqSubscriptionManager;
17
use PSB\Core\Transport\RabbitMq\RoutingTopology;
18
use PSB\Core\Util\Settings;
19
20
class RabbitMqTransportInfrastructure extends TransportInfrastructure
21
{
22
    /**
23
     * @var Settings
24
     */
25
    private $settings;
26
27
    /**
28
     * @var RoutingTopology
29
     */
30
    private $routingTopology;
31
32
    /**
33
     * @var BrokerModel
34
     */
35
    private $brokerModel;
36
37
    /**
38
     * @var bool
39
     */
40
    private $durableMessagesEnabled;
41
42
    /**
43
     * @param Settings        $settings
44
     * @param RoutingTopology $routingTopology
45
     * @param BrokerModel     $brokerModel
46
     * @param bool            $durableMessagesEnabled
47
     */
48 8
    public function __construct(
49
        Settings $settings,
50
        RoutingTopology $routingTopology,
51
        BrokerModel $brokerModel,
52
        $durableMessagesEnabled
53
    ) {
54 8
        $this->settings = $settings;
55 8
        $this->routingTopology = $routingTopology;
56 8
        $this->brokerModel = $brokerModel;
57 8
        $this->durableMessagesEnabled = $durableMessagesEnabled;
58 8
    }
59
60
    /**
61
     * @return TransportSendInfrastructure
62
     */
63 1
    public function configureSendInfrastructure()
64
    {
65 1
        return new TransportSendInfrastructure(
66
            function () {
67
                return new RabbitMqMessageDispatcher(
68
                    $this->routingTopology, $this->brokerModel, new MessageConverter()
69
                );
70 1
            }
71
        );
72
    }
73
74
    /**
75
     * @return TransportReceiveInfrastructure
76
     */
77 1
    public function configureReceiveInfrastructure()
78
    {
79 1
        return new TransportReceiveInfrastructure(
80
            function () {
81
                return new RabbitMqMessagePusher(
82
                    $this->brokerModel,
83
                    new MessageProcessor($this->brokerModel, $this->routingTopology, new MessageConverter())
84
                );
85 1
            },
86
            function () {
87
                return new RabbitMqQueueCreator(
88
                    $this->brokerModel,
89
                    $this->routingTopology,
90
                    $this->durableMessagesEnabled
91
                );
92 1
            }
93
        );
94
    }
95
96
    /**
97
     * @return TransportSubscriptionInfrastructure
98
     */
99 1
    public function configureSubscriptionInfrastructure()
100
    {
101 1
        return new TransportSubscriptionInfrastructure(
102
            function () {
103
                return new RabbitMqSubscriptionManager(
104
                    $this->brokerModel,
105
                    $this->routingTopology,
106
                    $this->getLocalAddress()
107
                );
108 1
            }
109
        );
110
    }
111
112
    /**
113
     * @param string $logicalAddress
114
     *
115
     * @return string
116
     */
117 2
    public function toTransportAddress($logicalAddress)
118
    {
119 2
        return RoutingTopology::getSafeName($logicalAddress);
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    private function getLocalAddress()
126
    {
127
        return $this->settings->get(KnownSettingsEnum::LOCAL_ADDRESS);
128
    }
129
}
130