PredisAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A isAvailable() 0 4 2
1
<?php
2
3
namespace NilPortugues\Cache\Adapter;
4
5
use NilPortugues\Cache\Adapter\Redis\AbstractAdapter;
6
use NilPortugues\Cache\CacheAdapter;
7
use Predis\Client;
8
9
/**
10
 * Class PredisAdapter
11
 * @package NilPortugues\Cache\Adapter\Redis
12
 */
13
class PredisAdapter extends AbstractAdapter
14
{
15
    /**
16
     * @param array           $connections
17
     * @param CacheAdapter    $next
18
     */
19
    public function __construct(array $connections, CacheAdapter $next = null)
20
    {
21
        $this->nextAdapter     = (InMemoryAdapter::getInstance() === $next) ? null: $next;
22
23
        try {
24
            $this->connected = true;
25
            $this->redis = new Client($connections);
26
            $this->redis->connect();
27
        } catch (\Exception $e) {
28
            $this->connected = false;
29
        }
30
    }
31
32
    /**
33
     * Checks the availability of the cache service.
34
     *
35
     * @return bool
36
     */
37
    public function isAvailable()
38
    {
39
        return $this->connected && $this->redis->isConnected();
40
    }
41
}
42