Completed
Push — master ( 6d1120...3e38c4 )
by Michal
10s
created

RedisDriver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 96.43%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 8
dl 0
loc 71
ccs 27
cts 28
cp 0.9643
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 4 2
A extensions() 0 4 1
A classes() 0 4 1
A type() 0 4 1
A defaultCredentials() 0 8 1
A getCredentialsForm() 0 4 1
A connect() 0 8 2
A getFormManager() 0 4 1
A getHeaderManager() 0 4 1
A getPermissions() 0 4 1
A getDataManager() 0 4 1
1
<?php
2
3
namespace UniMan\Drivers\Redis;
4
5
use RedisException;
6
use RedisProxy\RedisProxy;
7
use UniMan\Core\Driver\AbstractDriver;
8
use UniMan\Core\Exception\ConnectException;
9
use UniMan\Drivers\Redis\Forms\RedisCredentialsForm;
10
11
class RedisDriver extends AbstractDriver
12
{
13
    const TYPE_KEY = 'key';
14
    const TYPE_HASH = 'hash';
15
    const TYPE_SET = 'set';
16
17
    private $connection;
18
19 2
    public function check()
20
    {
21 2
        return extension_loaded('redis') || class_exists('Predis\Client');
22
    }
23
24 2
    public function extensions()
25
    {
26 2
        return ['redis'];
27
    }
28
29 2
    public function classes()
30
    {
31 2
        return ['Predis\Client'];
32
    }
33
34 2
    public function type()
35
    {
36 2
        return 'redis';
37
    }
38
39 2
    public function defaultCredentials()
40
    {
41
        return [
42 2
            'host' => 'localhost',
43 1
            'port' => '6379',
44 1
            'database' => '0',
45 1
        ];
46
    }
47
48 2
    public function getCredentialsForm()
49
    {
50 2
        return new RedisCredentialsForm();
51
    }
52
53 2
    public function connect(array $credentials)
54
    {
55
        try {
56 2
            $this->connection = new RedisProxy($credentials['host'], $credentials['port'], $credentials['database']);
57 1
        } catch (RedisException $e) {
58
            throw new ConnectException($e->getMessage());
59
        }
60 2
    }
61
62 2
    protected function getFormManager()
63
    {
64 2
        return new RedisFormManager($this->connection);
65
    }
66
67 2
    protected function getHeaderManager()
68
    {
69 2
        return new RedisHeaderManager();
70
    }
71
72 2
    protected function getPermissions()
73
    {
74 2
        return new RedisPermissions();
75
    }
76
77 2
    protected function getDataManager()
78
    {
79 2
        return new RedisDataManager($this->connection);
80
    }
81
}
82