RabbitMQCollection::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 23

Duplication

Lines 5
Ratio 21.74 %

Code Coverage

Tests 7
CRAP Score 8.125

Importance

Changes 0
Metric Value
dl 5
loc 23
ccs 7
cts 14
cp 0.5
rs 9.2408
c 0
b 0
f 0
cc 5
nc 6
nop 1
crap 8.125
1
<?php
2
3
namespace Liip\MonitorBundle\Check;
4
5
use Laminas\Diagnostics\Check\CheckCollectionInterface;
6
use Laminas\Diagnostics\Check\RabbitMQ;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
class RabbitMQCollection implements CheckCollectionInterface
12
{
13
    private $checks = [];
14
15 1
    public function __construct(array $configs)
16
    {
17 1
        foreach ($configs as $name => $config) {
18 1
            if (isset($config['dsn'])) {
19
                $config = array_merge($config, parse_url($config['dsn']));
20 View Code Duplication
                if (isset($config['pass'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 1
            $check = new RabbitMQ($config['host'], $config['port'], $config['user'], $config['password'], $config['vhost']);
33 1
            $check->setLabel(sprintf('Rabbit MQ "%s"', $name));
34
35 1
            $this->checks[sprintf('rabbit_mq_%s', $name)] = $check;
36
        }
37 1
    }
38
39 1
    public function getChecks()
40
    {
41 1
        return $this->checks;
42
    }
43
}
44