Passed
Push — master ( b520c6...4ddac5 )
by Mike
03:27
created

RabbitMQConfig   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 47
dl 0
loc 67
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConsumerConfig() 0 13 1
A getConnectionConfig() 0 20 1
1
<?php
2
3
4
namespace Xervice\RabbitMQ;
5
6
7
use DataProvider\RabbitMqConnectionConfigDataProvider;
8
use DataProvider\RabbitMqConsumerConfigDataProvider;
9
use Xervice\Core\Config\AbstractConfig;
10
11
class RabbitMQConfig extends AbstractConfig
12
{
13
    public const CONNECTION_HOST               = 'rabbitmq.connection.host';
14
    public const CONNECTION_PORT               = 'rabbitmq.connection.port';
15
    public const CONNECTION_USERNAME           = 'rabbitmq.connection.username';
16
    public const CONNECTION_PASSWORD           = 'rabbitmq.connection.password';
17
    public const CONNECTION_VIRTUALHOST        = 'rabbitmq.connection.virtualhost';
18
    public const CONNECTION_INSIST             = 'rabbitmq.connection.insist';
19
    public const CONNECTION_LOGIN_METHOD       = 'rabbitmq.connection.login.method';
20
    public const CONNECTION_LOCALE             = 'rabbitmq.connection.locale';
21
    public const CONNECTION_CONNECTION_TIMEOUT = 'rabbitmq.connection.connection.timeout';
22
    public const CONNECTION_READWRITE_TIMEOUT  = 'rabbitmq.connection.rewrite.timeout';
23
    public const CONNECTION_CONTEXT            = 'rabbitmq.connection.context';
24
    public const CONNECTION_KEEPALIVE          = 'rabbitmq.connection.keepalive';
25
    public const CONNECTION_HEARTBEAT          = 'rabbitmq.connection.hearthbeat';
26
27
28
    public const CONSUMER_TAG       = 'rabbitmq.consumer.tag';
29
    public const CONSUMER_NOLOCAL   = 'rabbitmq.consumer.nolocal';
30
    public const CONSUMER_NOACK     = 'rabbitmq.consumer.noack';
31
    public const CONSUMER_EXCLUSIVE = 'rabbitmq.consumer.exclusive';
32
    public const CONSUMER_NOWAIT    = 'rabbitmq.consumer.nowait';
33
    public const CONSUMER_TICKET    = 'rabbitmq.consumer.ticket';
34
    public const CONSUMER_ARGUMENTS = 'rabbitmq.consumer.arguments';
35
36
37
    /**
38
     * @return \DataProvider\RabbitMqConnectionConfigDataProvider
39
     */
40
    public function getConnectionConfig(): RabbitMqConnectionConfigDataProvider
41
    {
42
        $connectionConfig = new RabbitMqConnectionConfigDataProvider();
43
        $connectionConfig
44
            ->setHost($this->get(self::CONNECTION_HOST, '127.0.0.1'))
45
            ->setPort($this->get(self::CONNECTION_PORT, '5672'))
46
            ->setUsername($this->get(self::CONNECTION_USERNAME))
47
            ->setPassword($this->get(self::CONNECTION_PASSWORD))
48
            ->setVirtualHost($this->get(self::CONNECTION_VIRTUALHOST, '/'))
49
            ->setInsist($this->get(self::CONNECTION_INSIST, 'false'))
50
            ->setLoginMethod($this->get(self::CONNECTION_LOGIN_METHOD, 'AMQPLAIN'))
51
            ->setLocale($this->get(self::CONNECTION_LOCALE, 'de_DE'))
52
            ->setConnectionTimeout($this->get(self::CONNECTION_CONNECTION_TIMEOUT, 3.0))
53
            ->setReadWriteTimeout($this->get(self::CONNECTION_READWRITE_TIMEOUT, 3.0))
54
            ->setContext($this->get(self::CONNECTION_CONTEXT))
55
            ->setKeepAlive($this->get(self::CONNECTION_KEEPALIVE, false))
56
            ->setHeartbeat($this->get(self::CONNECTION_HEARTBEAT, 0))
57
        ;
58
59
        return $connectionConfig;
60
    }
61
62
    /**
63
     * @return \DataProvider\RabbitMqConsumerConfigDataProvider
64
     */
65
    public function getConsumerConfig(): RabbitMqConsumerConfigDataProvider
66
    {
67
        $consumerConfig = new RabbitMqConsumerConfigDataProvider();
68
        $consumerConfig
69
            ->setTag($this->get(self::CONSUMER_TAG, ''))
70
            ->setNoLocal($this->get(self::CONSUMER_NOLOCAL, false))
71
            ->setNoAck($this->get(self::CONSUMER_NOACK, false))
72
            ->setExclusive($this->get(self::CONSUMER_EXCLUSIVE, false))
73
            ->setNoWait($this->get(self::CONSUMER_NOWAIT, false))
74
            ->setTicket($this->get(self::CONSUMER_TICKET, null))
75
            ->setArguments($this->get(self::CONSUMER_ARGUMENTS, []));
76
77
        return $consumerConfig;
78
    }
79
}