Passed
Pull Request — master (#1601)
by Sam
06:27
created

Redis::__construct()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 10.5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 23
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 32
ccs 7
cts 14
cp 0.5
crap 10.5
rs 8.9297
1
<?php
2
3
namespace MySociety\TheyWorkForYou;
4
5
class Redis extends \Predis\Client {
6 1
    public function __construct() {
7 1
        if (REDIS_SENTINELS) {
0 ignored issues
show
Bug introduced by
The constant MySociety\TheyWorkForYou\REDIS_SENTINELS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
8 1
            $sentinels = array();
9 1
            $sentinel_port = REDIS_SENTINEL_PORT;
0 ignored issues
show
Bug introduced by
The constant MySociety\TheyWorkForYou\REDIS_SENTINEL_PORT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
10 1
            foreach (REDIS_SENTINELS as $sentinel) {
11
                // Wrap IPv6 addresses in square brackets
12 1
                if (filter_var($sentinel, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
13
                    $sentinel = "[${sentinel}]";
14
                }
15 1
                $sentinels[] = "tcp://${sentinel}:{$sentinel_port}?timeout=0.100";
16
            }
17
            $options = [
18
                'replication' => 'sentinel',
19
                'service' => REDIS_SERVICE_NAME,
0 ignored issues
show
Bug introduced by
The constant MySociety\TheyWorkForYou\REDIS_SERVICE_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
20
                'parameters' => [
21
                    'database' => REDIS_DB_NUMBER,
22
                ],
23
            ];
24
            if (REDIS_DB_PASSWORD) {
25
                $options['parameters']['password'] = REDIS_DB_PASSWORD;
26
            }
27
            parent::__construct($sentinels, $options);
28
        } else {
29
            $redis_args = [
30
                'host' => REDIS_DB_HOST,
31
                'port' => REDIS_DB_PORT,
32
                'db' => REDIS_DB_NUMBER,
33
            ];
34
            if (REDIS_DB_PASSWORD) {
35
                $redis_args['password'] = REDIS_DB_PASSWORD;
36
            }
37
            parent::__construct($redis_args);
38
        }
39 1
    }
40
}
41