Completed
Push — V6 ( cc1a0a...3a8b38 )
by Georges
04:31
created

ActOnAll::setItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
1
<?php
2
namespace phpFastCache\Helper;
3
4
use phpFastCache\CacheManager;
5
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
6
use Psr\Cache\CacheItemInterface;
7
8
/**
9
 * Class ActOnAll
10
 * @package phpFastCache\Helper
11
 */
12
class ActOnAll implements ExtendedCacheItemPoolInterface
13
{
14
    /**
15
     * @var array|\phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface[]
16
     */
17
    protected $instances = [];
18
19
    /**
20
     * ActOnAll constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->instances =& CacheManager::getInternalInstances();
25
    }
26
27
    /**
28
     * @return \Closure
29
     */
30
    protected function getGenericCallback()
31
    {
32
        return function($method, $args){
33
            $getterMethod = (strpos($method, 'get') === 0);
34
            $return = false;
35
36
            if($getterMethod){
37
                $return = [];
38
            }
39
40
            foreach ($this->instances as $instance)
41
            {
42
                if($getterMethod){
43
                    $return[ $instance->getDriverName() ] = $result = call_user_func_array([$instance, $method], $args);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
                }else{
45
                    $result = call_user_func_array([$instance, $method], $args);
46
                    if($return !== false){
47
                        $return = $result;
48
                    }
49
                }
50
            }
51
            return $return;
52
        };
53
    }
54
55
56
    /**
57
     * @param string $key
58
     * @return mixed
59
     */
60
    public function hasItem($key)
61
    {
62
        $callback = $this->getGenericCallback();
63
        return $callback(__METHOD__, func_get_args());
64
    }
65
66
    /**
67
     * @return mixed
68
     */
69
    public function clear()
70
    {
71
        $callback = $this->getGenericCallback();
72
        return $callback(__METHOD__, func_get_args());
73
    }
74
75
    /**
76
     * @param string $key
77
     * @return mixed
78
     */
79
    public function deleteItem($key)
80
    {
81
        $callback = $this->getGenericCallback();
82
        return $callback(__METHOD__, func_get_args());
83
    }
84
85
    /**
86
     * @param array $keys
87
     * @return mixed
88
     */
89
    public function deleteItems(array $keys)
90
    {
91
        $callback = $this->getGenericCallback();
92
        return $callback(__METHOD__, func_get_args());
93
    }
94
95
    /**
96
     * @param \Psr\Cache\CacheItemInterface $item
97
     * @return mixed
98
     */
99
    public function save(CacheItemInterface $item)
100
    {
101
        $callback = $this->getGenericCallback();
102
        return $callback(__METHOD__, func_get_args());
103
    }
104
105
    /**
106
     * @param \Psr\Cache\CacheItemInterface $item
107
     * @return mixed
108
     */
109
    public function saveDeferred(CacheItemInterface $item)
110
    {
111
        $callback = $this->getGenericCallback();
112
        return $callback(__METHOD__, func_get_args());
113
    }
114
115
    /**
116
     * @return mixed
117
     */
118
    public function commit()
119
    {
120
        $callback = $this->getGenericCallback();
121
        return $callback(__METHOD__, func_get_args());
122
    }
123
124
    /**
125
     * @return mixed
126
     */
127
    public function getConfig()
128
    {
129
        $callback = $this->getGenericCallback();
130
        return $callback(__METHOD__, func_get_args());
131
    }
132
133
    /**
134
     * @return mixed
135
     */
136
    public function getDriverName()
137
    {
138
        $callback = $this->getGenericCallback();
139
        return $callback(__METHOD__, func_get_args());
140
    }
141
142
    /**
143
     * @param string $key
144
     * @return mixed
145
     */
146
    public function getItem($key)
147
    {
148
        $callback = $this->getGenericCallback();
149
        return $callback(__METHOD__, func_get_args());
150
    }
151
152
    /**
153
     * @param array $keys
154
     * @return mixed
155
     */
156
    public function getItems(array $keys = [])
157
    {
158
        $callback = $this->getGenericCallback();
159
        return $callback(__METHOD__, func_get_args());
160
    }
161
162
    /**
163
     * @param array $keys
164
     * @param int $option
165
     * @param int $depth
166
     * @return mixed
167
     */
168
    public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512)
169
    {
170
        $callback = $this->getGenericCallback();
171
        return $callback(__METHOD__, func_get_args());
172
    }
173
174
    /**
175
     * @param \Psr\Cache\CacheItemInterface $item
176
     * @return mixed
177
     */
178
    public function setItem(CacheItemInterface $item)
179
    {
180
        $callback = $this->getGenericCallback();
181
        return $callback(__METHOD__, func_get_args());
182
    }
183
184
    /**
185
     * @return mixed
186
     */
187
    public function clean()
188
    {
189
        $callback = $this->getGenericCallback();
190
        return $callback(__METHOD__, func_get_args());
191
    }
192
193
    /**
194
     * @return mixed
195
     */
196
    public function getStats()
197
    {
198
        $callback = $this->getGenericCallback();
199
        return $callback(__METHOD__, func_get_args());
200
    }
201
202
    /**
203
     * @param string $tagName
204
     * @return mixed
205
     */
206
    public function getItemsByTag($tagName)
207
    {
208
        $callback = $this->getGenericCallback();
209
        return $callback(__METHOD__, func_get_args());
210
    }
211
212
    /**
213
     * @param array $tagNames
214
     * @return mixed
215
     */
216
    public function getItemsByTags(array $tagNames)
217
    {
218
        $callback = $this->getGenericCallback();
219
        return $callback(__METHOD__, func_get_args());
220
    }
221
222
    /**
223
     * @param array $tagNames
224
     * @param int $option
225
     * @param int $depth
226
     * @return mixed
227
     */
228
    public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512)
229
    {
230
        $callback = $this->getGenericCallback();
231
        return $callback(__METHOD__, func_get_args());
232
    }
233
234
    /**
235
     * @param string $tagName
236
     * @return mixed
237
     */
238
    public function deleteItemsByTag($tagName)
239
    {
240
        $callback = $this->getGenericCallback();
241
        return $callback(__METHOD__, func_get_args());
242
    }
243
244
    /**
245
     * @param array $tagNames
246
     * @return mixed
247
     */
248
    public function deleteItemsByTags(array $tagNames)
249
    {
250
        $callback = $this->getGenericCallback();
251
        return $callback(__METHOD__, func_get_args());
252
    }
253
254
    /**
255
     * @param string $tagName
256
     * @param int $step
257
     * @return mixed
258
     */
259
    public function incrementItemsByTag($tagName, $step = 1)
260
    {
261
        $callback = $this->getGenericCallback();
262
        return $callback(__METHOD__, func_get_args());
263
    }
264
265
    /**
266
     * @param array $tagNames
267
     * @param int $step
268
     * @return mixed
269
     */
270
    public function incrementItemsByTags(array $tagNames, $step = 1)
271
    {
272
        $callback = $this->getGenericCallback();
273
        return $callback(__METHOD__, func_get_args());
274
    }
275
276
    /**
277
     * @param string $tagName
278
     * @param int $step
279
     * @return mixed
280
     */
281
    public function decrementItemsByTag($tagName, $step = 1)
282
    {
283
        $callback = $this->getGenericCallback();
284
        return $callback(__METHOD__, func_get_args());
285
    }
286
287
    /**
288
     * @param array $tagNames
289
     * @param int $step
290
     * @return mixed
291
     */
292
    public function decrementItemsByTags(array $tagNames, $step = 1)
293
    {
294
        $callback = $this->getGenericCallback();
295
        return $callback(__METHOD__, func_get_args());
296
    }
297
298
    /**
299
     * @param string $tagName
300
     * @param array|string $data
301
     * @return mixed
302
     */
303
    public function appendItemsByTag($tagName, $data)
304
    {
305
        $callback = $this->getGenericCallback();
306
        return $callback(__METHOD__, func_get_args());
307
    }
308
309
    /**
310
     * @param array $tagNames
311
     * @param array|string $data
312
     * @return mixed
313
     */
314
    public function appendItemsByTags(array $tagNames, $data)
315
    {
316
        $callback = $this->getGenericCallback();
317
        return $callback(__METHOD__, func_get_args());
318
    }
319
320
    /**
321
     * @param string $tagName
322
     * @param array|string $data
323
     * @return mixed
324
     */
325
    public function prependItemsByTag($tagName, $data)
326
    {
327
        $callback = $this->getGenericCallback();
328
        return $callback(__METHOD__, func_get_args());
329
    }
330
331
    /**
332
     * @param array $tagNames
333
     * @param array|string $data
334
     * @return mixed
335
     */
336
    public function prependItemsByTags(array $tagNames, $data)
337
    {
338
        $callback = $this->getGenericCallback();
339
        return $callback(__METHOD__, func_get_args());
340
    }
341
342
    /**
343
     * @param \Psr\Cache\CacheItemInterface $item
344
     * @return mixed
345
     */
346
    public function detachItem(CacheItemInterface $item)
347
    {
348
        $callback = $this->getGenericCallback();
349
        return $callback(__METHOD__, func_get_args());
350
    }
351
352
    /**
353
     * @return mixed
354
     */
355
    public function detachAllItems()
356
    {
357
        $callback = $this->getGenericCallback();
358
        return $callback(__METHOD__, func_get_args());
359
    }
360
361
    /**
362
     * @param \Psr\Cache\CacheItemInterface $item
363
     * @return mixed
364
     */
365
    public function attachItem(CacheItemInterface $item)
366
    {
367
        $callback = $this->getGenericCallback();
368
        return $callback(__METHOD__, func_get_args());
369
    }
370
371
    /**
372
     * @param \Psr\Cache\CacheItemInterface $item
373
     * @return mixed
374
     */
375
    public function isAttached(CacheItemInterface $item)
376
    {
377
        $callback = $this->getGenericCallback();
378
        return $callback(__METHOD__, func_get_args());
379
    }
380
}