Completed
Push — master ( 9a1e57...9eab6b )
by Kamil
02:30
created

ApiCoreTrait   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 153
Duplicated Lines 5.23 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 45.83%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 1
dl 8
loc 153
ccs 22
cts 48
cp 0.4583
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
dispatch() 0 1 ?
A bgRewriteAoF() 0 6 1
A bgSave() 0 6 1
A sync() 0 7 1
A time() 0 7 1
A monitor() 0 7 1
A flushAll() 0 6 1
A flushDb() 0 7 1
C info() 0 34 8
A slaveOf() 8 8 1
A save() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Dazzle\Redis\Command\Compose;
4
5
use Dazzle\Redis\Command\Builder;
6
use Dazzle\Redis\Command\Enum;
7
use Dazzle\Redis\Driver\Request;
8
9
trait ApiCoreTrait
10
{
11
    /**
12
     * @param Request $request
13
     * @return mixed
14
     */
15
    abstract function dispatch(Request $request);
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
17
    /**
18
     * @override
19
     * @inheritDoc
20
     */
21
    public function bgRewriteAoF()
22
    {
23
        $command = Enum::BGREWRITEAOF;
24
25
        return $this->dispatch(Builder::build($command));
26
    }
27
28
    /**
29
     * @override
30
     * @inheritDoc
31
     */
32
    public function bgSave()
33
    {
34
        $command = Enum::BGSAVE;
35
36
        return $this->dispatch(Builder::build($command));
37
    }
38
39
    /**
40
     * @override
41
     * @inheritDoc
42
     */
43
    public function sync()
44
    {
45
        // TODO: Implement sync() method.
46
        $command = Enum::SYNC;
47
48
        return $this->dispatch(Builder::build($command));
49
    }
50
51
    /**
52
     * @override
53
     * @inheritDoc
54
     */
55
    public function time()
56
    {
57
        // TODO: Implement time() method.
58
        $command = Enum::TIME;
59
60
        return $this->dispatch(Builder::build($command));
61
    }
62
63
    /**
64
     * @override
65
     * @inheritDoc
66
     */
67
    public function monitor()
68
    {
69
        // TODO: Implement monitor() method.
70
        $command = Enum::MONITOR;
71
72
        return $this->dispatch(Builder::build($command));
73
    }
74
75
    /**
76
     * @override
77
     * @inheritDoc
78
     */
79
    public function flushAll()
80
    {
81
        $command = Enum::FLUSHALL;
82
83
        return $this->dispatch(Builder::build($command));
84
    }
85
86
    /**
87
     * @override
88
     * @inheritDoc
89
     */
90 1
    public function flushDb()
91
    {
92
        // TODO: Implement flushDb() method.
93 1
        $command = Enum::FLUSHDB;
94
95 1
        return $this->dispatch(Builder::build($command));
96
    }
97
98
    /**
99
     * @override
100
     * @inheritDoc
101
     */
102 1
    public function info($section = [])
103
    {
104 1
        $command = Enum::INFO;
105
106 1
        return $this->dispatch(Builder::build($command, $section))->then(function ($value) {
107 1
            if ($value) {
108 1
                $ret = explode("\r\n", $value);
109 1
                $handled = [];
110 1
                $lastKey = '';
111
112 1
                foreach ($ret as $_ => $v)
113
                {
114 1
                    if (($pos = strpos($v, '#')) !== false)
115
                    {
116 1
                        $lastKey = strtolower(substr($v,$pos+2));
117 1
                        $handled[$lastKey] = [];
118 1
                        continue;
119
                    }
120 1
                    if ($v === '') {
121 1
                        continue;
122
                    }
123 1
                    if (($statMap = explode(':', $v)) && $statMap[0] && $statMap[1])
124
                    {
125 1
                        list($name, $stat) = explode(':', $v);
126 1
                        $handled[$lastKey][$name] = $stat;
127
                    }
128
                }
129
130 1
                return $handled;
131
            }
132
133
            return $value;
134 1
        });
135
    }
136
137
    /**
138
     * @override
139
     * @inheritDoc
140
     */
141 View Code Duplication
    public function slaveOf($host, $port)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
    {
143
        // TODO: Implement slaveOf() method.
144
        $command = Enum::SLAVEOF;
145
        $args = [$host, $port];
146
147
        return $this->dispatch(Builder::build($command, $args));
148
    }
149
150
    /**
151
     * @override
152
     * @inheritDoc
153
     */
154
    public function save()
155
    {
156
        // TODO: Implement save() method.
157
        $command = Enum::SAVE;
158
159
        return $this->dispatch(Builder::build($command));
160
    }
161
}
162