Completed
Pull Request — master (#19)
by Michal
03:25
created

RedisDriver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 96.55%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 8
dl 0
loc 72
ccs 28
cts 29
cp 0.9655
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 getHeaderManager() 0 4 1
A getPermissions() 0 4 1
A connect() 0 9 2
A getFormManager() 0 4 1
A getDataManager() 0 4 1
1
<?php
2
3
namespace Adminerng\Drivers\Redis;
4
5
use Adminerng\Core\Driver\AbstractDriver;
6
use Adminerng\Core\Exception\ConnectException;
7
use Adminerng\Drivers\Redis\Forms\RedisCredentialsForm;
8
use RedisException;
9
use RedisProxy\RedisProxy;
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 2
            $this->connection->select($credentials['database']);
58 1
        } catch (RedisException $e) {
59
            throw new ConnectException($e->getMessage());
60
        }
61 2
    }
62
63 2
    protected function getFormManager()
64
    {
65 2
        return new RedisFormManager($this->connection);
66
    }
67
68 2
    protected function getHeaderManager()
69
    {
70 2
        return new RedisHeaderManager();
71
    }
72
73 2
    protected function getPermissions()
74
    {
75 2
        return new RedisPermissions();
76
    }
77
78 2
    protected function getDataManager()
79
    {
80 2
        return new RedisDataManager($this->connection);
81
    }
82
}
83