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

ApiListTrait::lTrim()   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
nc 1
cc 1
eloc 4
nop 3
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 ApiListTrait
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 View Code Duplication
    public function blPop(array $keys, $timeout)
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...
22
    {
23
        // TODO: Implement blPop() method.
24
        $command = Enum::BLPOP;
25
        $keys[] = $timeout;
26
        $args = $keys;
27
        $promise = $this->dispatch(Builder::build($command, $args));
28
        $promise = $promise->then(function ($value) {
29
            if (is_array($value)) {
30
                list($k,$v) = $value;
31
32
                return [
33
                    'key'=>$k,
34
                    'value'=>$v
35
                ];
36
            }
37
38
            return $value;
39
        });
40
41
        return $promise;
42
    }
43
44
    /**
45
     * @override
46
     * @inheritDoc
47
     */
48 View Code Duplication
    public function brPop(array $keys, $timeout)
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...
49
    {
50
        // TODO: Implement brPop() method.
51
        $command = Enum::BRPOP;
52
        $keys[] = $timeout;
53
        $args = $keys;
54
        $promise = $this->dispatch(Builder::build($command, $args));
55
        $promise = $promise->then(function ($value) {
56
            if (is_array($value)) {
57
                list($k,$v) = $value;
58
59
                return [
60
                    'key'=>$k,
61
                    'value'=>$v
62
                ];
63
            }
64
65
            return $value;
66
        });
67
68
        return $promise;
69
    }
70
71
    /**
72
     * @override
73
     * @inheritDoc
74
     */
75
    public function brPopLPush($src, $dst, $timeout)
76
    {
77
        // TODO: Implement brPopLPush() method.
78
        $command = Enum::BRPOPLPUSH;
79
        $args = [$src, $dst, $timeout];
80
81
        return $this->dispatch(Builder::build($command, $args));
82
    }
83
84
    /**
85
     * @override
86
     * @inheritDoc
87
     */
88
    public function lIndex($key, $index)
89
    {
90
        // TODO: Implement lIndex() method.
91
        $command = Enum::LINDEX;
92
        $args = [$key, $index];
93
94
        return $this->dispatch(Builder::build($command, $args));
95
    }
96
97
    /**
98
     * @override
99
     * @inheritDoc
100
     */
101
    public function lInsert($key, $action, $pivot, $value)
102
    {
103
        // TODO: Implement lInsert() method.
104
        $command = Enum::LINSERT;
105
        $args = [$key, $action, $pivot, $value];
106
107
        return $this->dispatch(Builder::build($command, $args));
108
    }
109
110
    /**
111
     * @override
112
     * @inheritDoc
113
     */
114 View Code Duplication
    public function lLen($key)
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...
115
    {
116
        // TODO: Implement lLen() method.
117
        $command = Enum::LLEN;
118
        $args = [$key];
119
120
        return $this->dispatch(Builder::build($command, $args));
121
    }
122
123
    /**
124
     * @override
125
     * @inheritDoc
126
     */
127 View Code Duplication
    public function lPop($key)
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...
128
    {
129
        // TODO: Implement lPop() method.
130
        $command = Enum::LPOP;
131
        $args = [$key];
132
133
        return $this->dispatch(Builder::build($command, $args));
134
    }
135
136
    /**
137
     * @override
138
     * @inheritDoc
139
     */
140
    public function lPush($key,...$values)
141
    {
142
        $command = Enum::LPUSH;
143
        array_unshift($values, $key);
144
145
        return $this->dispatch(Builder::build($command, $values));
146
    }
147
148
    public function lPushX($key, $value)
149
    {
150
        $command = Enum::LPUSHX;
151
        $args = [$key, $value];
152
153
        return $this->dispatch(Builder::build($command, $args));
154
    }
155
156
    /**
157
     * @override
158
     * @inheritDoc
159
     */
160
    public function lRange($key, $start = 0, $stop = -1)
161
    {
162
        $command = Enum::LRANGE;
163
        $args = [$key, $start, $stop];
164
165
        return $this->dispatch(Builder::build($command, $args));
166
    }
167
168
    /**
169
     * @override
170
     * @inheritDoc
171
     */
172
    public function lRem($key, $count, $value)
173
    {
174
        // TODO: Implement lRem() method.
175
        $command = Enum::LREM;
176
        $args = [$key, $count, $value];
177
178
        return $this->dispatch(Builder::build($command, $args));
179
    }
180
181
    /**
182
     * @override
183
     * @inheritDoc
184
     */
185
    public function lSet($key, $index, $value)
186
    {
187
        // TODO: Implement lSet() method.
188
        $command = Enum::LSET;
189
        $args = [$key, $index, $value];
190
191
        return $this->dispatch(Builder::build($command, $args));
192
    }
193
194
    /**
195
     * @override
196
     * @inheritDoc
197
     */
198
    public function lTrim($key, $start, $stop)
199
    {
200
        // TODO: Implement lTrim() method.
201
        $command = Enum::LTRIM;
202
        $args = [$key, $start, $stop];
203
204
        return $this->dispatch(Builder::build($command, $args));
205
    }
206
207
    /**
208
     * @override
209
     * @inheritDoc
210
     */
211 View Code Duplication
    public function rPop($key)
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...
212
    {
213
        $command = Enum::RPOP;
214
        $args = [$key];
215
216
        return $this->dispatch(Builder::build($command, $args));
217
    }
218
219
    /**
220
     * @override
221
     * @inheritDoc
222
     */
223 View Code Duplication
    public function rPopLPush($src, $dst)
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...
224
    {
225
        // TODO: Implement rPopLPush() method.
226
        $command = Enum::RPOPLPUSH;
227
        $args = [$src, $dst];
228
229
        return $this->dispatch(Builder::build($command, $args));
230
    }
231
232
    /**
233
     * @override
234
     * @inheritDoc
235
     */
236
    public function rPush($key, ...$values)
237
    {
238
        $command = Enum::RPUSH;
239
        $args = [$key];
240
        $args = array_merge($args, $values);
241
242
        return $this->dispatch(Builder::build($command, $args));
243
    }
244
245
    /**
246
     * @override
247
     * @inheritDoc
248
     */
249
    public function rPushX($key, $value)
250
    {
251
        $command = Enum::RPUSHX;
252
        $args = [$key, $value];
253
254
        return $this->dispatch(Builder::build($command, $args));
255
    }
256
}
257