RedisCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 52.38 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 22
loc 42
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 3
A parseDsn() 9 18 3
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\Redis;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
class RedisCollection implements CheckCollectionInterface
12
{
13
    private $checks = [];
14
15 3 View Code Duplication
    public function __construct(array $configs)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
16
    {
17 3
        foreach ($configs as $name => $config) {
18 3
            if (isset($config['dsn'])) {
19 2
                $this->parseDsn($config);
20
            }
21
22 3
            $check = new Redis($config['host'], $config['port'], $config['password']);
23 3
            $check->setLabel(\sprintf('Redis "%s"', $name));
24
25 3
            $this->checks[\sprintf('redis_%s', $name)] = $check;
26
        }
27 3
    }
28
29 2
    private function parseDsn(array &$config)
30
    {
31 2
        $config = \array_merge($config, \parse_url($config['dsn']));
32
33 2
        if (isset($config['pass'])) {
34 1
            $config['password'] = $config['pass'];
35
            // Cleanup
36 1
            unset($config['pass']);
37 1 View Code Duplication
        } elseif (isset($config['user'])) {
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...
38
            /*
39
             * since "redis://my-super-secret-password@redis-host:6379" is a valid redis
40
             * dsn but \parse_url does not understand this notation and extracts the auth as user,
41
             * we need to check for it.
42
             */
43 1
            $config['password'] = $config['user'];
44 1
            unset($config['user']);
45
        }
46 2
    }
47
48 3
    public function getChecks()
49
    {
50 3
        return $this->checks;
51
    }
52
}
53