Completed
Push — master ( f9dee5...20d667 )
by Lukas Kahwe
13s queued 10s
created

RabbitMQCollection::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.5906
c 0
b 0
f 0
cc 5
eloc 13
nc 6
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
                if (isset($config['pass'])) {
21
                    $config['password'] = $config['pass'];
22
                    // Cleanup
23
                    unset($config['pass']);
24
                }
25
                if (isset($config['path'])) {
26
                    $config['vhost'] = urldecode(substr($config['path'], 1));
27
                    // Cleanup
28
                    unset($config['path']);
29
                }
30
            }
31
32
            $check = new RabbitMQ($config['host'], $config['port'], $config['user'], $config['password'], $config['vhost']);
33
            $check->setLabel(sprintf('Rabbit MQ "%s"', $name));
34
35
            $this->checks[sprintf('rabbit_mq_%s', $name)] = $check;
36
        }
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getChecks()
43
    {
44
        return $this->checks;
45
    }
46
}
47