ConsumerConfiguration   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 92
ccs 49
cts 49
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B generate() 0 63 4
1
<?php
2
3
namespace MyOnlineStore\Bundle\RabbitMqManagerBundle\Configuration\Consumer;
4
5
use MyOnlineStore\Bundle\RabbitMqManagerBundle\Configuration\Section\SectionCollection;
6
7
class ConsumerConfiguration
8
{
9
    /**
10
     * @var ConsumerSectionFactoryInterface
11
     */
12
    private $sectionFactory;
13
14
    /**
15
     * @var string
16
     */
17
    private $path;
18
19
    /**
20
     * @param ConsumerSectionFactoryInterface $sectionFactory
21
     * @param string                          $path
22
     */
23 3
    public function __construct(ConsumerSectionFactoryInterface $sectionFactory, $path)
24
    {
25 3
        $this->sectionFactory = $sectionFactory;
26 3
        $this->path = $path;
27 3
    }
28
29
    /**
30
     * @param array       $consumer
31
     * @param null|string $route
32
     *
33
     * @return SectionCollection
34
     */
35 3
    public function generate(array $consumer, $route = null)
36
    {
37 3
        $sections = new SectionCollection();
38
39 3
        $sections->addSection(
40 3
            $this->sectionFactory->createRabbitmq(
41
                [
42 3
                    'host' => $consumer['connection']['host'],
43 3
                    'username' => $consumer['connection']['user'],
44 3
                    'password' => $consumer['connection']['password'],
45 3
                    'vhost' => $consumer['connection']['vhost'],
46 3
                    'port' => $consumer['connection']['port'],
47 3
                    'queue' => $consumer['worker']['queue']['name'],
48 3
                    'compression' => $consumer['worker']['compression'],
49
                ]
50 3
            )
51 3
        );
52
53 3
        if ($consumer['worker']['prefetch']['count'] > 0) {
54 2
            $sections->addSection(
55 2
                $this->sectionFactory->createPrefetch(
56
                    [
57 2
                        'count' => $consumer['worker']['prefetch']['count'],
58 2
                        'global' => $consumer['worker']['prefetch']['global'],
59
                    ]
60 2
                )
61 2
            );
62 2
        }
63
64 3
        if (isset($consumer['worker']['exchange'])) {
65 2
            $sections->addSection(
66 2
                $this->sectionFactory->createExchange(
67
                    [
68 2
                        'name' => $consumer['worker']['exchange']['name'],
69 2
                        'type' => $consumer['worker']['exchange']['type'],
70 2
                        'durable' => $consumer['worker']['exchange']['durable'],
71 2
                        'autodelete' => $consumer['worker']['exchange']['autodelete'],
72
                    ]
73 2
                )
74 2
            );
75 2
        }
76
77 3
        if (null !== $route) {
78 2
            $sections->addSection(
79 2
                $this->sectionFactory->createQueue(
80
                    [
81 2
                        'routingkey' => $route,
82
                    ]
83 2
                )
84 2
            );
85 2
        }
86
87 3
        $sections->addSection(
88 3
            $this->sectionFactory->createLogs(
89
                [
90 3
                    'info' => sprintf('%s/consumer.log', $this->path),
91 3
                    'error' => sprintf('%s/consumer.err', $this->path),
92
                ]
93 3
            )
94 3
        );
95
96 3
        return $sections;
97
    }
98
}
99