Completed
Pull Request — master (#176)
by
unknown
01:56
created

RabbitMQCollection::__construct()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 11
nc 9
nop 1
1
<?php
2
3
namespace Liip\MonitorBundle\Check;
4
5
use ZendDiagnostics\Check\CheckCollectionInterface;
6
use ZendDiagnostics\Check\RabbitMQ;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
class RabbitMQCollection implements CheckCollectionInterface
12
{
13
    private $checks = array();
14
15
    public function __construct(array $configs)
16
    {
17
        foreach ($configs as $name => $config) {
18
            if (isset($config['dsn'])) {
19
                $config = array_merge($config, parse_url($config['dsn']));
20
            }
21
22
            if (isset($config['pass'])) {
23
                $config['password'] = $config['pass'];
24
            }
25
26
            if (isset($config['path'])) {
27
                $config['vhost'] = urldecode(substr($config['path'], 1));
28
            }
29
30
            $check = new RabbitMQ($config['host'], $config['port'], $config['user'], $config['password'], $config['vhost']);
31
            $check->setLabel(sprintf('Rabbit MQ "%s"', $name));
32
33
            $this->checks[sprintf('rabbit_mq_%s', $name)] = $check;
34
        }
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getChecks()
41
    {
42
        return $this->checks;
43
    }
44
}
45