RabbitMQCollection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 15.15 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 56.25%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 5
loc 33
ccs 9
cts 16
cp 0.5625
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 23 5
A getChecks() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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