RedisConnectCheck::performCheck()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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