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

ApiCoreTrait::monitor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 9.4285
nc 1
cc 1
eloc 3
nop 0
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 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