Completed
Push — master ( 01354b...bfe60b )
by Kamil
12s
created

ApiCoreTrait::slowLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 2
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 96
    public function flushDb()
91
    {
92
        // TODO: Implement flushDb() method.
93 96
        $command = Enum::FLUSHDB;
94
95 96
        return $this->dispatch(Builder::build($command));
96
    }
97
98
    /**
99
     * @override
100
     * @inheritDoc
101
     */
102 96
    public function info($section = [])
103
    {
104 96
        $command = Enum::INFO;
105
106 96
        return $this->dispatch(Builder::build($command, $section))->then(function ($value) {
107 96
            if ($value) {
108 96
                $ret = explode("\r\n", $value);
109 96
                $handled = [];
110 96
                $lastKey = '';
111
112 96
                foreach ($ret as $_ => $v)
113
                {
114 96
                    if (($pos = strpos($v, '#')) !== false)
115
                    {
116 96
                        $lastKey = strtolower(substr($v,$pos+2));
117 96
                        $handled[$lastKey] = [];
118 96
                        continue;
119
                    }
120 96
                    if ($v === '') {
121 96
                        continue;
122
                    }
123 96
                    if (($statMap = explode(':', $v)) && $statMap[0] && $statMap[1])
124
                    {
125 96
                        list($name, $stat) = explode(':', $v);
126 96
                        $handled[$lastKey][$name] = $stat;
127
                    }
128
                }
129
130 96
                return $handled;
131
            }
132
133
            return $value;
134 96
        });
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 slowLog($command, array $args = [])
0 ignored issues
show
Unused Code introduced by
The parameter $command is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
155
    {
156
        // TODO: Implement sLowLog() method.
157
        $command = Enum::SLOWLOG;
158
        $args = array_merge([$command],$args);
159
160
        return $this->dispatch(Builder::build($command, $args));
161
    }
162
163
    /**
164
     * @override
165
     * @inheritDoc
166
     */
167
    public function save()
168
    {
169
        // TODO: Implement save() method.
170
        $command = Enum::SAVE;
171
172
        return $this->dispatch(Builder::build($command));
173
    }
174
}
175