Completed
Push — master ( 9e125a...9a1e57 )
by Kamil
02:25
created

ApiCoreTrait   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 147
Duplicated Lines 5.44 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 6.38%

Importance

Changes 0
Metric Value
dl 8
loc 147
c 0
b 0
f 0
wmc 14
lcom 1
cbo 1
ccs 3
cts 47
cp 0.0638
rs 10

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
B info() 0 28 5
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
    public function info($section = [])
103
    {
104
        $command = Enum::INFO;
105
106
        return $this->dispatch(Builder::build($command, $section))->then(function ($value) {
107
            if ($value) {
108
                $ret = explode(PHP_EOL, $value);
109
                $handled = [];
110
                $lastKey = '';
111
                foreach ($ret as $_ => $v) {
112
                    if (($pos = strpos($v, '#')) !== false) {
113
                        $lastKey = strtolower(substr($v,$pos+2));
114
                        $handled[$lastKey] = [];
115
                        continue;
116
                    }
117
                    $statMap = explode(':', $v);
118
                    if ($statMap[0]) {
119
                        list($name, $stat) = explode(':', $v);
120
                        $handled[$lastKey][$name] = $stat;
121
                    }
122
                }
123
124
                return $handled;
125
            }
126
127
            return $value;
128
        });
129
    }
130
131
    /**
132
     * @override
133
     * @inheritDoc
134
     */
135 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...
136
    {
137
        // TODO: Implement slaveOf() method.
138
        $command = Enum::SLAVEOF;
139
        $args = [$host, $port];
140
141
        return $this->dispatch(Builder::build($command, $args));
142
    }
143
144
    /**
145
     * @override
146
     * @inheritDoc
147
     */
148
    public function save()
149
    {
150
        // TODO: Implement save() method.
151
        $command = Enum::SAVE;
152
153
        return $this->dispatch(Builder::build($command));
154
    }
155
}
156