RedisCollection::parseDsn()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 9
Ratio 50 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 9
loc 18
ccs 9
cts 9
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
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