@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) |
40 | 40 | { |
41 | - $callback = function (CacheItemInterface $item) { |
|
41 | + $callback = function(CacheItemInterface $item) { |
|
42 | 42 | return $item->get(); |
43 | 43 | }; |
44 | 44 | return json_encode(array_map($callback, array_values($this->getItems($keys))), $option, $depth); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | if (is_string($tagName)) { |
53 | 53 | $driverResponse = $this->getItem($this->getTagKey($tagName)); |
54 | 54 | if ($driverResponse->isHit()) { |
55 | - $items = (array)$driverResponse->get(); |
|
55 | + $items = (array) $driverResponse->get(); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * getItems() may provides expired item(s) |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * #headache |
66 | 66 | */ |
67 | - return array_filter($this->getItems(array_unique(array_keys($items))), function (ExtendedCacheItemInterface $item) { |
|
67 | + return array_filter($this->getItems(array_unique(array_keys($items))), function(ExtendedCacheItemInterface $item) { |
|
68 | 68 | return $item->isHit(); |
69 | 69 | }); |
70 | 70 | } else { |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | { |
83 | 83 | $items = []; |
84 | 84 | foreach (array_unique($tagNames) as $tagName) { |
85 | - if(is_string($tagName)){ |
|
85 | + if (is_string($tagName)) { |
|
86 | 86 | $items = array_merge($items, $this->getItemsByTag($tagName)); |
87 | - }else{ |
|
87 | + } else { |
|
88 | 88 | throw new InvalidArgumentException('$tagName must be a a string'); |
89 | 89 | } |
90 | 90 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | foreach ($items as $key => $item) { |
104 | 104 | if (array_diff($tagNames, $item->getTags())) { |
105 | - unset($items[ $key ]); |
|
105 | + unset($items[$key]); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
117 | 117 | { |
118 | - $callback = function (CacheItemInterface $item) { |
|
118 | + $callback = function(CacheItemInterface $item) { |
|
119 | 119 | return $item->get(); |
120 | 120 | }; |
121 | 121 | |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | */ |
387 | 387 | public function detachItem(CacheItemInterface $item) |
388 | 388 | { |
389 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
389 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
390 | 390 | $this->deregisterItem($item); |
391 | 391 | } |
392 | 392 | } |
@@ -406,10 +406,10 @@ discard block |
||
406 | 406 | */ |
407 | 407 | public function attachItem(CacheItemInterface $item) |
408 | 408 | { |
409 | - if (isset($this->itemInstances[ $item->getKey() ]) && spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])) { |
|
409 | + if (isset($this->itemInstances[$item->getKey()]) && spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
410 | 410 | throw new \LogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.'); |
411 | 411 | } else { |
412 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
412 | + $this->itemInstances[$item->getKey()] = $item; |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | protected function deregisterItem($item) |
423 | 423 | { |
424 | 424 | if ($item instanceof CacheItemInterface) { |
425 | - unset($this->itemInstances[ $item->getKey() ]); |
|
425 | + unset($this->itemInstances[$item->getKey()]); |
|
426 | 426 | |
427 | 427 | } else if (is_string($item)) { |
428 | - unset($this->itemInstances[ $item ]); |
|
428 | + unset($this->itemInstances[$item]); |
|
429 | 429 | } else { |
430 | 430 | throw new \InvalidArgumentException('Invalid type for $item variable'); |
431 | 431 | } |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function isAttached(CacheItemInterface $item) |
447 | 447 | { |
448 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
449 | - return spl_object_hash($item) === spl_object_hash($this->itemInstances[ $item->getKey() ]); |
|
448 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
449 | + return spl_object_hash($item) === spl_object_hash($this->itemInstances[$item->getKey()]); |
|
450 | 450 | } |
451 | 451 | return null; |
452 | 452 | } |
@@ -466,8 +466,8 @@ discard block |
||
466 | 466 | */ |
467 | 467 | public function saveMultiple(...$items) |
468 | 468 | { |
469 | - if (isset($items[ 0 ]) && is_array($items[ 0 ])) { |
|
470 | - foreach ($items[ 0 ] as $item) { |
|
469 | + if (isset($items[0]) && is_array($items[0])) { |
|
470 | + foreach ($items[0] as $item) { |
|
471 | 471 | $this->save($item); |
472 | 472 | } |
473 | 473 | return true; |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | require_once __DIR__ . '/../src/autoload.php'; |
12 | 12 | echo '[PhpFastCache API v' . Api::getVersion() . "]\n\n"; |
13 | 13 | |
14 | -$defaultDriver = (!empty($argv[ 1 ]) ? ucfirst($argv[ 1 ]) : 'Files'); |
|
14 | +$defaultDriver = (!empty($argv[1]) ? ucfirst($argv[1]) : 'Files'); |
|
15 | 15 | $status = 0; |
16 | 16 | echo "Testing items tags feature\n"; |
17 | 17 | |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | echo "\n#1 Testing getter: getItemsByTag() // Expecting 3 results\n"; |
70 | 70 | |
71 | 71 | $tagsItems = $driverInstance->getItemsByTag('tag-test_all'); |
72 | -if(is_array($tagsItems)) |
|
72 | +if (is_array($tagsItems)) |
|
73 | 73 | { |
74 | - if(count($tagsItems) === 3) |
|
74 | + if (count($tagsItems) === 3) |
|
75 | 75 | { |
76 | - foreach($tagsItems as $tagsItem) |
|
76 | + foreach ($tagsItems as $tagsItem) |
|
77 | 77 | { |
78 | - if(!in_array($tagsItem->getKey(), ['tag-test1', 'tag-test2', 'tag-test3'])){ |
|
79 | - echo '[FAIL] STEP#1 // Got unexpected tagged item key:' . $tagsItem->getKey() . "\n"; |
|
78 | + if (!in_array($tagsItem->getKey(), ['tag-test1', 'tag-test2', 'tag-test3'])) { |
|
79 | + echo '[FAIL] STEP#1 // Got unexpected tagged item key:' . $tagsItem->getKey() . "\n"; |
|
80 | 80 | $status = 1; |
81 | 81 | goto itemTagTest2; |
82 | 82 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | } |
86 | 86 | else |
87 | 87 | { |
88 | - echo '[FAIL] STEP#1 //Got wrong count of item:' . count($tagsItems) . "\n"; |
|
88 | + echo '[FAIL] STEP#1 //Got wrong count of item:' . count($tagsItems) . "\n"; |
|
89 | 89 | $status = 1; |
90 | 90 | goto itemTagTest2; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | else |
94 | 94 | { |
95 | - echo '[FAIL] STEP#1 // Expected $tagsItems to be an array, got: ' . gettype($tagsItems) . "\n"; |
|
95 | + echo '[FAIL] STEP#1 // Expected $tagsItems to be an array, got: ' . gettype($tagsItems) . "\n"; |
|
96 | 96 | $status = 1; |
97 | 97 | goto itemTagTest2; |
98 | 98 | } |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | |
108 | 108 | $tagsItems = $driverInstance->getItemsByTagsAll(['tag-test_all', 'tag-test_all2', 'tag-test_all3']); |
109 | 109 | |
110 | -if(is_array($tagsItems)) |
|
110 | +if (is_array($tagsItems)) |
|
111 | 111 | { |
112 | - if(count($tagsItems) === 3) |
|
112 | + if (count($tagsItems) === 3) |
|
113 | 113 | { |
114 | - foreach($tagsItems as $tagsItem) |
|
114 | + foreach ($tagsItems as $tagsItem) |
|
115 | 115 | { |
116 | - if(!in_array($tagsItem->getKey(), ['tag-test1', 'tag-test2', 'tag-test3'])){ |
|
117 | - echo '[FAIL] STEP#2 // Got unexpected tagged item key:' . $tagsItem->getKey() . "\n"; |
|
116 | + if (!in_array($tagsItem->getKey(), ['tag-test1', 'tag-test2', 'tag-test3'])) { |
|
117 | + echo '[FAIL] STEP#2 // Got unexpected tagged item key:' . $tagsItem->getKey() . "\n"; |
|
118 | 118 | $status = 1; |
119 | 119 | goto itemTagTest3; |
120 | 120 | } |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | } |
124 | 124 | else |
125 | 125 | { |
126 | - echo '[FAIL] STEP#2 // Got wrong count of item:' . count($tagsItems) . "\n"; |
|
126 | + echo '[FAIL] STEP#2 // Got wrong count of item:' . count($tagsItems) . "\n"; |
|
127 | 127 | $status = 1; |
128 | 128 | goto itemTagTest3; |
129 | 129 | } |
130 | 130 | } |
131 | 131 | else |
132 | 132 | { |
133 | - echo '[FAIL] STEP#2 // Expected $tagsItems to be an array, got: ' . gettype($tagsItems) . "\n"; |
|
133 | + echo '[FAIL] STEP#2 // Expected $tagsItems to be an array, got: ' . gettype($tagsItems) . "\n"; |
|
134 | 134 | $status = 1; |
135 | 135 | goto itemTagTest3; |
136 | 136 | } |
@@ -145,14 +145,14 @@ discard block |
||
145 | 145 | |
146 | 146 | $tagsItems = $driverInstance->getItemsByTagsAll(['tag-test_all', 'tag-test_all2', 'tag-test_all3', 'tag-test_all4']); |
147 | 147 | |
148 | -if(is_array($tagsItems)) |
|
148 | +if (is_array($tagsItems)) |
|
149 | 149 | { |
150 | - if(count($tagsItems) === 1) |
|
150 | + if (count($tagsItems) === 1) |
|
151 | 151 | { |
152 | - if(isset($tagsItems['tag-test3'])) |
|
152 | + if (isset($tagsItems['tag-test3'])) |
|
153 | 153 | { |
154 | - if($tagsItems['tag-test3']->getKey() !== 'tag-test3'){ |
|
155 | - echo '[FAIL] STEP#3 // Got unexpected tagged item key:' . $tagsItems['tag-test3']->getKey() . "\n"; |
|
154 | + if ($tagsItems['tag-test3']->getKey() !== 'tag-test3') { |
|
155 | + echo '[FAIL] STEP#3 // Got unexpected tagged item key:' . $tagsItems['tag-test3']->getKey() . "\n"; |
|
156 | 156 | $status = 1; |
157 | 157 | goto itemTagTest4; |
158 | 158 | } |
@@ -160,21 +160,21 @@ discard block |
||
160 | 160 | } |
161 | 161 | else |
162 | 162 | { |
163 | - echo '[FAIL] STEP#3 // Got wrong array key, expected "tag-test3", got "' . key($tagsItems) . "\"\n"; |
|
163 | + echo '[FAIL] STEP#3 // Got wrong array key, expected "tag-test3", got "' . key($tagsItems) . "\"\n"; |
|
164 | 164 | $status = 1; |
165 | 165 | goto itemTagTest4; |
166 | 166 | } |
167 | 167 | } |
168 | 168 | else |
169 | 169 | { |
170 | - echo '[FAIL] STEP#3 // Got wrong count of item:' . count($tagsItems) . "\n"; |
|
170 | + echo '[FAIL] STEP#3 // Got wrong count of item:' . count($tagsItems) . "\n"; |
|
171 | 171 | $status = 1; |
172 | 172 | goto itemTagTest4; |
173 | 173 | } |
174 | 174 | } |
175 | 175 | else |
176 | 176 | { |
177 | - echo '[FAIL] STEP#3 // Expected $tagsItems to be an array, got: ' . gettype($tagsItems) . "\n"; |
|
177 | + echo '[FAIL] STEP#3 // Expected $tagsItems to be an array, got: ' . gettype($tagsItems) . "\n"; |
|
178 | 178 | $status = 1; |
179 | 179 | goto itemTagTest4; |
180 | 180 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $createItemsCallback(); |
189 | 189 | $driverInstance->deleteItemsByTag('tag-test_all'); |
190 | 190 | |
191 | -if(count($driverInstance->getItemsByTag('tag-test_all')) > 0) |
|
191 | +if (count($driverInstance->getItemsByTag('tag-test_all')) > 0) |
|
192 | 192 | { |
193 | 193 | echo "[FAIL] STEP#4 // Getter getItemsByTag() found item(s), possible memory leak \n"; |
194 | 194 | $status = 1; |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | $i = 0; |
202 | -while(++$i <= 3) |
|
202 | +while (++$i <= 3) |
|
203 | 203 | { |
204 | - if($driverInstance->getItem("tag-test{$i}")->isHit()) |
|
204 | + if ($driverInstance->getItem("tag-test{$i}")->isHit()) |
|
205 | 205 | { |
206 | 206 | echo "[FAIL] STEP#4 // Item 'tag-test{$i}' should've been deleted and is still in cache storage \n"; |
207 | 207 | $status = 1; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | |
223 | 223 | $driverInstance->deleteItemsByTagsAll(['tag-test_all', 'tag-test_all2', 'tag-test_all3']); |
224 | 224 | |
225 | -if(count($driverInstance->getItemsByTag('tag-test_all')) > 0) |
|
225 | +if (count($driverInstance->getItemsByTag('tag-test_all')) > 0) |
|
226 | 226 | { |
227 | 227 | echo "[FAIL] STEP#5 // Getter getItemsByTag() found item(s), possible memory leak \n"; |
228 | 228 | $status = 1; |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | } |
234 | 234 | |
235 | 235 | $i = 0; |
236 | -while(++$i <= 3) |
|
236 | +while (++$i <= 3) |
|
237 | 237 | { |
238 | - if($driverInstance->getItem("tag-test{$i}")->isHit()) |
|
238 | + if ($driverInstance->getItem("tag-test{$i}")->isHit()) |
|
239 | 239 | { |
240 | 240 | echo "[FAIL] STEP#5 // Item 'tag-test{$i}' should've been deleted and is still in cache storage \n"; |
241 | 241 | $status = 1; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | */ |
260 | 260 | $driverInstance->deleteItemsByTagsAll(['tag-test_all', 'tag-test_all2', 'tag-test_all3', 'tag-test_all4']); |
261 | 261 | |
262 | -if($driverInstance->getItem('item-test_3')->isHit()) |
|
262 | +if ($driverInstance->getItem('item-test_3')->isHit()) |
|
263 | 263 | { |
264 | 264 | echo "[FAIL] STEP#6 // Getter getItem() found item 'item-test_3', possible memory leak \n"; |
265 | 265 | $status = 1; |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | $appendStr = '$*#*$'; |
280 | 280 | $driverInstance->appendItemsByTagsAll(['tag-test_all', 'tag-test_all2', 'tag-test_all3'], $appendStr); |
281 | 281 | |
282 | -foreach($driverInstance->getItems(['tag-test1', 'tag-test2', 'tag-test3']) as $item) |
|
282 | +foreach ($driverInstance->getItems(['tag-test1', 'tag-test2', 'tag-test3']) as $item) |
|
283 | 283 | { |
284 | - if(strpos($item->get(), $appendStr) === false) |
|
284 | + if (strpos($item->get(), $appendStr) === false) |
|
285 | 285 | { |
286 | 286 | echo "[FAIL] STEP#7 // Item '{$item->getKey()}' does not have the string part '{$appendStr}' in it's value \n"; |
287 | 287 | $status = 1; |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | $prependStr = '&+_+&'; |
303 | 303 | $driverInstance->prependItemsByTagsAll(['tag-test_all', 'tag-test_all2', 'tag-test_all3'], $prependStr); |
304 | 304 | |
305 | -foreach($driverInstance->getItems(['tag-test1', 'tag-test2', 'tag-test3']) as $item) |
|
305 | +foreach ($driverInstance->getItems(['tag-test1', 'tag-test2', 'tag-test3']) as $item) |
|
306 | 306 | { |
307 | - if(strpos($item->get(), $prependStr) === false) |
|
307 | + if (strpos($item->get(), $prependStr) === false) |
|
308 | 308 | { |
309 | 309 | echo "[FAIL] STEP#7 // Item '{$item->getKey()}' does not have the string part '{$prependStr}' in it's value \n"; |
310 | 310 | $status = 1; |