RedisConnectCheck::getClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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