Completed
Push — master ( b586f8...cd674c )
by Kamil
12s
created

ApiCoreTrait::time()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
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 1
    public function bgRewriteAoF()
22
    {
23 1
        $command = Enum::BGREWRITEAOF;
24
25 1
        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
        $command = Enum::SYNC;
46
47
        return $this->dispatch(Builder::build($command));
48
    }
49
50
    /**
51
     * @override
52
     * @inheritDoc
53
     */
54 1
    public function time()
55
    {
56 1
        $command = Enum::TIME;
57
58 1
        return $this->dispatch(Builder::build($command));
59
    }
60
61
    /**
62
     * @override
63
     * @inheritDoc
64
     */
65 1
    public function monitor()
66
    {
67 1
        $command = Enum::MONITOR;
68
69 1
        return $this->dispatch(Builder::build($command));
70
    }
71
72
    /**
73
     * @override
74
     * @inheritDoc
75
     */
76 1
    public function flushAll()
77
    {
78 1
        $command = Enum::FLUSHALL;
79
80 1
        return $this->dispatch(Builder::build($command));
81
    }
82
83
    /**
84
     * @override
85
     * @inheritDoc
86
     */
87 21
    public function flushDb()
88
    {
89 21
        $command = Enum::FLUSHDB;
90
91 21
        return $this->dispatch(Builder::build($command));
92
    }
93
94
    /**
95
     * @override
96
     * @inheritDoc
97
     */
98 21
    public function info($section = [])
99
    {
100 21
        $command = Enum::INFO;
101
102 21
        return $this->dispatch(Builder::build($command, $section))->then(function ($value) {
103 21
            if ($value) {
104 21
                $ret = explode("\r\n", $value);
105 21
                $handled = [];
106 21
                $lastKey = '';
107
108 21
                foreach ($ret as $_ => $v)
109
                {
110 21
                    if (($pos = strpos($v, '#')) !== false)
111
                    {
112 21
                        $lastKey = strtolower(substr($v,$pos+2));
113 21
                        $handled[$lastKey] = [];
114 21
                        continue;
115
                    }
116 21
                    if ($v === '') {
117 21
                        continue;
118
                    }
119 21
                    if (($statMap = explode(':', $v)) && $statMap[0] && $statMap[1])
120
                    {
121 21
                        list($name, $stat) = explode(':', $v);
122 21
                        $handled[$lastKey][$name] = $stat;
123
                    }
124
                }
125
126 21
                return $handled;
127
            }
128
129
            return $value;
130 21
        });
131
    }
132
133
    /**
134
     * @override
135
     * @inheritDoc
136
     */
137 1 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...
138
    {
139 1
        $command = Enum::SLAVEOF;
140 1
        $args = [$host, $port];
141
142 1
        return $this->dispatch(Builder::build($command, $args));
143
    }
144
145
    /**
146
     * @override
147
     * @inheritDoc
148
     */
149
    public function slowLog($subCommand, array $args = [])
150
    {
151
        $command = Enum::SLOWLOG;
152
        $args = array_merge([$subCommand],$args);
153
154
        return $this->dispatch(Builder::build($command, $args));
155
    }
156
157
    /**
158
     * @override
159
     * @inheritDoc
160
     */
161
    public function save()
162
    {
163
        $command = Enum::SAVE;
164
165
        return $this->dispatch(Builder::build($command));
166
    }
167
}
168