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

RabbitMQCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 23 5
A getChecks() 0 4 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