Completed
Push — master ( d09c43...626232 )
by Thibaud
02:18
created

AmqpConfiguration   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 121
ccs 40
cts 40
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 21 1
A extractValueOrDefault() 0 4 2
A getHost() 0 4 1
A getVhost() 0 4 1
A getPort() 0 4 1
A getUser() 0 4 1
A getPassword() 0 4 1
A getDeadLetterExchange() 0 4 1
A getExchange() 0 4 1
A getQueue() 0 4 1
A toConnectionArray() 0 10 1
1
<?php
2
3
namespace Alchemy\Queue\Amqp;
4
5
class AmqpConfiguration
6
{
7
8 12
    public static function parse(array $parameters)
9
    {
10 12
        $configuration = new self();
11
12 12
        $configuration->host = self::extractValueOrDefault($parameters, 'host', $configuration->host);
13 12
        $configuration->vhost = self::extractValueOrDefault($parameters, 'vhost', $configuration->vhost);
14 12
        $configuration->port = self::extractValueOrDefault($parameters, 'port', $configuration->port);
15 12
        $configuration->user = self::extractValueOrDefault($parameters, 'user', $configuration->user);
16 12
        $configuration->password = self::extractValueOrDefault($parameters, 'password', $configuration->password);
17 12
        $configuration->exchange = self::extractValueOrDefault($parameters, 'exchange', $configuration->exchange);
18
19 12
        $configuration->deadLetterExchange = self::extractValueOrDefault(
20 9
            $parameters,
21 12
            'dead-letter-exchange',
22 12
            $configuration->deadLetterExchange
23 9
        );
24
25 12
        $configuration->queue = self::extractValueOrDefault($parameters, 'queue', $configuration->queue);
26
27 12
        return $configuration;
28
    }
29
30 12
    private static function extractValueOrDefault(array $parameters, $key, $default = null)
31
    {
32 12
        return isset($parameters[$key]) ? $parameters[$key] : $default;
33
    }
34
35
    private $host = 'localhost';
36
37
    private $vhost = '/';
38
39
    private $port = 5672;
40
41
    private $user = 'guest';
42
43
    private $password = 'guest';
44
45
    private $deadLetterExchange = 'alchemy-dead-exchange';
46
47
    private $exchange = 'alchemy-exchange';
48
49
    private $queue = 'alchemy-queue';
50
51
    /**
52
     * @return string
53
     */
54 8
    public function getHost()
55
    {
56 8
        return $this->host;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 8
    public function getVhost()
63
    {
64 8
        return $this->vhost;
65
    }
66
67
    /**
68
     * @return int
69
     */
70 8
    public function getPort()
71
    {
72 8
        return $this->port;
73
    }
74
75
    /**
76
     * @return string
77
     */
78 8
    public function getUser()
79
    {
80 8
        return $this->user;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 8
    public function getPassword()
87
    {
88 8
        return $this->password;
89
    }
90
91
    /**
92
     * @return string
93
     */
94 12
    public function getDeadLetterExchange()
95
    {
96 12
        return $this->deadLetterExchange;
97
    }
98
99
    /**
100
     * @return string
101
     */
102 12
    public function getExchange()
103
    {
104 12
        return $this->exchange;
105
    }
106
107
    /**
108
     * @return string
109
     */
110 8
    public function getQueue()
111
    {
112 8
        return $this->queue;
113
    }
114
115 8
    public function toConnectionArray()
116
    {
117
        return [
118 8
            'host' => $this->host,
119 8
            'port' => $this->port,
120 8
            'vhost' => $this->vhost,
121 8
            'login' => $this->user,
122 8
            'password' => $this->password
123 6
        ];
124
    }
125
}
126
127