RabbitMqTransportDefinition   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 8
dl 0
loc 59
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createConfigurator() 0 4 1
A createConnectionFactory() 0 4 1
A formalize() 0 12 1
A isDurableMessagingEnabled() 0 10 2
1
<?php
2
namespace PSB\Core\Transport\RabbitMq\Config;
3
4
5
use AMQPConnection;
6
use PSB\Core\KnownSettingsEnum;
7
use PSB\Core\Transport\Config\TransportDefinition;
8
use PSB\Core\Transport\RabbitMq\AmqpConnectionFactory;
9
use PSB\Core\Transport\RabbitMq\BrokerModel;
10
use PSB\Core\Transport\RabbitMq\RoutingTopology;
11
use PSB\Core\Transport\TransportConnectionFactoryInterface;
12
use PSB\Core\Util\Settings;
13
14
class RabbitMqTransportDefinition extends TransportDefinition
15
{
16
    /**
17
     * @param Settings $settings
18
     *
19
     * @return RabbitMqTransportConfigurator
20
     */
21 1
    public function createConfigurator(Settings $settings)
22
    {
23 1
        return new RabbitMqTransportConfigurator($settings);
24
    }
25
26
    /**
27
     * Creates the TransportConnectionFactory specific to the transport implementation.
28
     *
29
     * @param Settings $settings
30
     *
31
     * @return AmqpConnectionFactory
32
     */
33 1
    public function createConnectionFactory(Settings $settings)
34
    {
35 1
        return new AmqpConnectionFactory($settings);
36
    }
37
38
    /**
39
     * @param Settings                            $settings
40
     * @param TransportConnectionFactoryInterface $connectionFactory
41
     *
42
     * @return RabbitMqTransportInfrastructure
43
     */
44 2
    public function formalize(Settings $settings, TransportConnectionFactoryInterface $connectionFactory)
45
    {
46 2
        $durableMessagingEnabled = $this->isDurableMessagingEnabled($settings);
47
        /** @var AMQPConnection $connection */
48 2
        $connection = $connectionFactory->createConnection();
49 2
        return new RabbitMqTransportInfrastructure(
50 2
            $settings,
51 2
            new RoutingTopology($durableMessagingEnabled),
52 2
            new BrokerModel($connection),
53 2
            $durableMessagingEnabled
54
        );
55
    }
56
57
    /**
58
     * @param Settings $settings
59
     *
60
     * @return bool
61
     */
62 2
    private function isDurableMessagingEnabled(Settings $settings)
63
    {
64 2
        $enabled = $settings->tryGet(KnownSettingsEnum::DURABLE_MESSAGING_ENABLED);
65
66 2
        if ($enabled === null) {
67 1
            $enabled = true;
68
        }
69
70 2
        return $enabled;
71
    }
72
}
73