RedisConnectCheck   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 49
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A performCheck() 0 8 2
A getClient() 0 4 1
A setClient() 0 4 1
1
<?php
2
3
namespace TonicHealthCheck\Check\Redis\Connect;
4
5
use Predis\Client as PredisClient;
6
use Predis\PredisException;
7
use TonicHealthCheck\Check\Redis\AbstractRedisCheck;
8
9
/**
10
 * Class RedisConnectCheck.
11
 */
12
class RedisConnectCheck extends AbstractRedisCheck
13
{
14
    const CHECK = 'redis-connect-check';
15
16
    /**
17
     * @var PredisClient
18
     */
19
    protected $client;
20
21
    /**
22
     * @param string       $checkNode
23
     * @param PredisClient $client
24
     */
25 3
    public function __construct($checkNode, PredisClient $client)
26
    {
27 3
        parent::__construct($checkNode);
28 3
        $this->setClient($client);
29 3
    }
30
31
    /**
32
     * Check PredisClient can connect to redis server.
33
     *
34
     * @throws RedisConnectCheckException
35
     */
36 3
    public function performCheck()
37
    {
38
        try {
39 3
            $this->getClient()->connect();
40 2
        } catch (PredisException $e) {
41 1
            throw  RedisConnectCheckException::connectProblem($e);
42
        }
43 1
    }
44
45
    /**
46
     * @return PredisClient
47
     */
48 3
    public function getClient()
49
    {
50 3
        return $this->client;
51
    }
52
53
    /**
54
     * @param PredisClient $client
55
     */
56 3
    protected function setClient(PredisClient $client)
57
    {
58 3
        $this->client = $client;
59 3
    }
60
}
61