@@ -41,8 +41,7 @@ discard block |
||
41 | 41 | * @param $args |
42 | 42 | * ArrayObject constructor. |
43 | 43 | */ |
44 | - public function __construct(...$args) |
|
45 | - { |
|
44 | + public function __construct(...$args) { |
|
46 | 45 | $this->array = (count($args) === 1 && is_array($args[0]) ? $args[0] : $args); |
47 | 46 | } |
48 | 47 | |
@@ -50,8 +49,7 @@ discard block |
||
50 | 49 | * @return mixed |
51 | 50 | */ |
52 | 51 | #[\ReturnTypeWillChange] // PHP 8.1 compatibility |
53 | - public function current() |
|
54 | - { |
|
52 | + public function current() { |
|
55 | 53 | return $this->array[$this->position]; |
56 | 54 | } |
57 | 55 | |
@@ -109,8 +107,7 @@ discard block |
||
109 | 107 | * @return mixed |
110 | 108 | */ |
111 | 109 | #[\ReturnTypeWillChange] // PHP 8.1 compatibility |
112 | - public function offsetGet($offset) |
|
113 | - { |
|
110 | + public function offsetGet($offset) { |
|
114 | 111 | return $this->array[$offset] ?? null; |
115 | 112 | } |
116 | 113 | |
@@ -125,7 +122,8 @@ discard block |
||
125 | 122 | |
126 | 123 | if ($offset === null) { |
127 | 124 | $this->array[] = $value; |
128 | - } else { |
|
125 | + } |
|
126 | + else { |
|
129 | 127 | $this->array[$offset] = $value; |
130 | 128 | } |
131 | 129 | } |
@@ -106,7 +106,8 @@ discard block |
||
106 | 106 | break; |
107 | 107 | } |
108 | 108 | } |
109 | - }else{ |
|
109 | + } |
|
110 | + else{ |
|
110 | 111 | while (isset($tokens[++$i][1])) { |
111 | 112 | if (\in_array($tokens[$i][0], [T_STRING, T_NS_SEPARATOR], true)) { |
112 | 113 | $namespace .= $tokens[$i][1]; |
@@ -127,7 +128,8 @@ discard block |
||
127 | 128 | if (T_DOUBLE_COLON === $tokens[$j][0]) { |
128 | 129 | $isClassConstant = true; |
129 | 130 | break; |
130 | - } elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
131 | + } |
|
132 | + elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
131 | 133 | break; |
132 | 134 | } |
133 | 135 | } |
@@ -139,7 +141,8 @@ discard block |
||
139 | 141 | $t = $tokens[$i]; |
140 | 142 | if (T_STRING === $t[0]) { |
141 | 143 | $class .= $t[1]; |
142 | - } elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
144 | + } |
|
145 | + elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
143 | 146 | break; |
144 | 147 | } |
145 | 148 | } |
@@ -61,8 +61,7 @@ discard block |
||
61 | 61 | * @param $key |
62 | 62 | * @throws PhpfastcacheInvalidArgumentException |
63 | 63 | */ |
64 | - public function __construct(ExtendedCacheItemPoolInterface $driver, $key) |
|
65 | - { |
|
64 | + public function __construct(ExtendedCacheItemPoolInterface $driver, $key) { |
|
66 | 65 | if (\is_string($key)) { |
67 | 66 | $this->key = $key; |
68 | 67 | $this->driver = $driver; |
@@ -74,7 +73,8 @@ discard block |
||
74 | 73 | $this->creationDate = new DateTime(); |
75 | 74 | $this->modificationDate = new DateTime(); |
76 | 75 | } |
77 | - } else { |
|
76 | + } |
|
77 | + else { |
|
78 | 78 | throw new PhpfastcacheInvalidArgumentTypeException('string', $key); |
79 | 79 | } |
80 | 80 | } |
@@ -89,7 +89,8 @@ discard block |
||
89 | 89 | |
90 | 90 | if ($keyHashFunction) { |
91 | 91 | $this->encodedKey = $keyHashFunction($this->getKey()); |
92 | - } else { |
|
92 | + } |
|
93 | + else { |
|
93 | 94 | $this->encodedKey = $this->getKey(); |
94 | 95 | } |
95 | 96 | } |
@@ -247,7 +248,8 @@ discard block |
||
247 | 248 | if (\is_int($step)) { |
248 | 249 | $this->fetched = true; |
249 | 250 | $this->data += $step; |
250 | - } else { |
|
251 | + } |
|
252 | + else { |
|
251 | 253 | throw new PhpfastcacheInvalidArgumentException('$step must be numeric.'); |
252 | 254 | } |
253 | 255 | |
@@ -264,7 +266,8 @@ discard block |
||
264 | 266 | if (\is_int($step)) { |
265 | 267 | $this->fetched = true; |
266 | 268 | $this->data -= $step; |
267 | - } else { |
|
269 | + } |
|
270 | + else { |
|
268 | 271 | throw new PhpfastcacheInvalidArgumentException('$step must be numeric.'); |
269 | 272 | } |
270 | 273 | |
@@ -280,10 +283,12 @@ discard block |
||
280 | 283 | { |
281 | 284 | if (\is_array($this->data)) { |
282 | 285 | $this->data[] = $data; |
283 | - } else { |
|
286 | + } |
|
287 | + else { |
|
284 | 288 | if (\is_string($data)) { |
285 | 289 | $this->data .= (string)$data; |
286 | - } else { |
|
290 | + } |
|
291 | + else { |
|
287 | 292 | throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); |
288 | 293 | } |
289 | 294 | } |
@@ -301,10 +306,12 @@ discard block |
||
301 | 306 | { |
302 | 307 | if (\is_array($this->data)) { |
303 | 308 | \array_unshift($this->data, $data); |
304 | - } else { |
|
309 | + } |
|
310 | + else { |
|
305 | 311 | if (\is_string($data)) { |
306 | 312 | $this->data = (string)$data . $this->data; |
307 | - } else { |
|
313 | + } |
|
314 | + else { |
|
308 | 315 | throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); |
309 | 316 | } |
310 | 317 | } |
@@ -325,7 +332,8 @@ discard block |
||
325 | 332 | |
326 | 333 | if (\is_object($data) || \is_array($data)) { |
327 | 334 | $data = \json_encode($data, $option, $depth); |
328 | - } else { |
|
335 | + } |
|
336 | + else { |
|
329 | 337 | $data = \json_encode([$data], $option, $depth); |
330 | 338 | } |
331 | 339 | |
@@ -337,8 +345,7 @@ discard block |
||
337 | 345 | * @return mixed |
338 | 346 | */ |
339 | 347 | #[\ReturnTypeWillChange] // PHP 8.1 compatibility |
340 | - public function jsonSerialize() |
|
341 | - { |
|
348 | + public function jsonSerialize() { |
|
342 | 349 | return $this->get(); |
343 | 350 | } |
344 | 351 | |
@@ -358,8 +365,7 @@ discard block |
||
358 | 365 | * |
359 | 366 | * Prevent recursions for Debug (php 5.6+) |
360 | 367 | */ |
361 | - final public function __debugInfo() |
|
362 | - { |
|
368 | + final public function __debugInfo() { |
|
363 | 369 | $info = \get_object_vars($this); |
364 | 370 | $info['driver'] = 'object(' . \get_class($info['driver']) . ')'; |
365 | 371 |
@@ -66,7 +66,8 @@ |
||
66 | 66 | if (\count($tags)) { |
67 | 67 | if (\array_filter($tags, 'is_string')) { |
68 | 68 | $this->tags = $tags; |
69 | - } else { |
|
69 | + } |
|
70 | + else { |
|
70 | 71 | throw new PhpfastcacheInvalidArgumentException('$tagName must be an array of string'); |
71 | 72 | } |
72 | 73 | } |
@@ -86,16 +86,14 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - public function getKey() |
|
90 | - { |
|
89 | + public function getKey() { |
|
91 | 90 | return $this->key; |
92 | 91 | } |
93 | 92 | |
94 | 93 | /** |
95 | 94 | * @return mixed |
96 | 95 | */ |
97 | - public function get() |
|
98 | - { |
|
96 | + public function get() { |
|
99 | 97 | return $this->data; |
100 | 98 | } |
101 | 99 | |
@@ -103,8 +101,7 @@ discard block |
||
103 | 101 | * @param mixed $value |
104 | 102 | * @return $this |
105 | 103 | */ |
106 | - public function set($value) |
|
107 | - { |
|
104 | + public function set($value) { |
|
108 | 105 | /** |
109 | 106 | * The user set a value, |
110 | 107 | * therefore there is no need to |
@@ -163,7 +160,8 @@ discard block |
||
163 | 160 | */ |
164 | 161 | $this->eventManager->dispatch('CacheItemExpireAt', $this, $expiration); |
165 | 162 | $this->expirationDate = $expiration; |
166 | - } else { |
|
163 | + } |
|
164 | + else { |
|
167 | 165 | throw new PhpfastcacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration)); |
168 | 166 | } |
169 | 167 | |
@@ -175,8 +173,7 @@ discard block |
||
175 | 173 | * @return $this |
176 | 174 | * @throws PhpfastcacheInvalidArgumentException |
177 | 175 | */ |
178 | - public function expiresAfter($time) |
|
179 | - { |
|
176 | + public function expiresAfter($time) { |
|
180 | 177 | if (\is_numeric($time)) { |
181 | 178 | if ($time <= 0) { |
182 | 179 | /** |
@@ -194,7 +191,8 @@ discard block |
||
194 | 191 | $this->eventManager->dispatch('CacheItemExpireAfter', $this, $time); |
195 | 192 | |
196 | 193 | $this->expirationDate = (new DateTime())->add(new DateInterval(\sprintf('PT%dS', $time))); |
197 | - } else { |
|
194 | + } |
|
195 | + else { |
|
198 | 196 | if ($time instanceof DateInterval) { |
199 | 197 | /** |
200 | 198 | * @eventName CacheItemExpireAt |
@@ -204,7 +202,8 @@ discard block |
||
204 | 202 | $this->eventManager->dispatch('CacheItemExpireAfter', $this, $time); |
205 | 203 | |
206 | 204 | $this->expirationDate = (new DateTime())->add($time); |
207 | - } else { |
|
205 | + } |
|
206 | + else { |
|
208 | 207 | throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid date format, got "%s"', \gettype($time))); |
209 | 208 | } |
210 | 209 | } |
@@ -49,8 +49,7 @@ discard block |
||
49 | 49 | /** |
50 | 50 | * @inheritdoc |
51 | 51 | */ |
52 | - public function detachAllItems() |
|
53 | - { |
|
52 | + public function detachAllItems() { |
|
54 | 53 | foreach ($this->itemInstances as $item) { |
55 | 54 | $this->detachItem($item); |
56 | 55 | } |
@@ -60,8 +59,7 @@ discard block |
||
60 | 59 | * @param CacheItemInterface $item |
61 | 60 | * @return void |
62 | 61 | */ |
63 | - public function detachItem(CacheItemInterface $item) |
|
64 | - { |
|
62 | + public function detachItem(CacheItemInterface $item) { |
|
65 | 63 | if (isset($this->itemInstances[$item->getKey()])) { |
66 | 64 | $this->deregisterItem($item->getKey()); |
67 | 65 | } |
@@ -71,8 +69,7 @@ discard block |
||
71 | 69 | * @param string $item |
72 | 70 | * @internal This method de-register an item from $this->itemInstances |
73 | 71 | */ |
74 | - protected function deregisterItem(string $item) |
|
75 | - { |
|
72 | + protected function deregisterItem(string $item) { |
|
76 | 73 | unset($this->itemInstances[$item]); |
77 | 74 | |
78 | 75 | if (\gc_enabled()) { |
@@ -83,8 +80,7 @@ discard block |
||
83 | 80 | /** |
84 | 81 | * @inheritdoc |
85 | 82 | */ |
86 | - public function attachItem(CacheItemInterface $item) |
|
87 | - { |
|
83 | + public function attachItem(CacheItemInterface $item) { |
|
88 | 84 | if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { |
89 | 85 | throw new PhpfastcacheLogicException( |
90 | 86 | '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.' |
@@ -108,8 +104,7 @@ discard block |
||
108 | 104 | * @param CacheItemInterface $item |
109 | 105 | * @return bool|null |
110 | 106 | */ |
111 | - public function isAttached(CacheItemInterface $item) |
|
112 | - { |
|
107 | + public function isAttached(CacheItemInterface $item) { |
|
113 | 108 | if (isset($this->itemInstances[$item->getKey()])) { |
114 | 109 | return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]); |
115 | 110 | } |
@@ -50,7 +50,8 @@ discard block |
||
50 | 50 | foreach (\array_unique($tagNames) as $tagName) { |
51 | 51 | if (\is_string($tagName)) { |
52 | 52 | $items[] = $this->fetchItemsByTagFromBackend($tagName); |
53 | - } else { |
|
53 | + } |
|
54 | + else { |
|
54 | 55 | throw new PhpfastcacheInvalidArgumentException('$tagName must be a a string'); |
55 | 56 | } |
56 | 57 | } |
@@ -310,8 +311,7 @@ discard block |
||
310 | 311 | * @param array $wrapper |
311 | 312 | * @return mixed |
312 | 313 | */ |
313 | - protected function driverUnwrapTags(array $wrapper) |
|
314 | - { |
|
314 | + protected function driverUnwrapTags(array $wrapper) { |
|
315 | 315 | return $wrapper[self::DRIVER_TAGS_WRAPPER_INDEX]; |
316 | 316 | } |
317 | 317 | |
@@ -320,8 +320,7 @@ discard block |
||
320 | 320 | * @throws PhpfastcacheInvalidArgumentException |
321 | 321 | * @throws PhpfastcacheLogicException |
322 | 322 | */ |
323 | - protected function cleanItemTags(ExtendedCacheItemInterface $item) |
|
324 | - { |
|
323 | + protected function cleanItemTags(ExtendedCacheItemInterface $item) { |
|
325 | 324 | $this->driverWriteTags($item->removeTags($item->getTags())); |
326 | 325 | } |
327 | 326 | |
@@ -391,7 +390,8 @@ discard block |
||
391 | 390 | $tagsItem->expiresAt((new DateTime())->setTimestamp(max($data))); |
392 | 391 | $this->driverWrite($tagsItem); |
393 | 392 | $tagsItem->setHit(true); |
394 | - } else { |
|
393 | + } |
|
394 | + else { |
|
395 | 395 | $this->deleteItem($tagsItem->getKey()); |
396 | 396 | } |
397 | 397 | } |
@@ -66,7 +66,8 @@ discard block |
||
66 | 66 | |
67 | 67 | if($this->getConfig()->isUseStaticItemCaching()){ |
68 | 68 | $stat->setData(implode(', ', \array_keys($this->itemInstances))); |
69 | - }else{ |
|
69 | + } |
|
70 | + else{ |
|
70 | 71 | $stat->setData('No data available since static item caching option (useStaticItemCaching) is disabled.'); |
71 | 72 | } |
72 | 73 | |
@@ -123,7 +124,8 @@ discard block |
||
123 | 124 | if (!$securityKey || \mb_strtolower($securityKey) === 'auto') { |
124 | 125 | if (isset($_SERVER['HTTP_HOST'])) { |
125 | 126 | $securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $_SERVER['HTTP_HOST']))); |
126 | - } else { |
|
127 | + } |
|
128 | + else { |
|
127 | 129 | $securityKey = ($this->isPHPModule() ? 'web' : 'cli'); |
128 | 130 | } |
129 | 131 | } |
@@ -143,7 +145,8 @@ discard block |
||
143 | 145 | |
144 | 146 | if (empty($this->getConfig()->getPath())) { |
145 | 147 | $path = $tmp_dir; |
146 | - } else { |
|
148 | + } |
|
149 | + else { |
|
147 | 150 | $path = \rtrim($this->getConfig()->getPath(), '/') . DIRECTORY_SEPARATOR; |
148 | 151 | } |
149 | 152 | |
@@ -170,7 +173,8 @@ discard block |
||
170 | 173 | if (@mkdir($full_path, $this->getDefaultChmod(), true) === false && !\is_dir($full_path)) { |
171 | 174 | throw new PhpfastcacheIOException('The directory ' . $full_path . ' could not be created.'); |
172 | 175 | } |
173 | - } else { |
|
176 | + } |
|
177 | + else { |
|
174 | 178 | if (!@\is_writable($full_path)) { |
175 | 179 | if (!@\chmod($full_path, $this->getDefaultChmod()) && $this->getConfig()->isAutoTmpFallback()) { |
176 | 180 | /** |
@@ -238,15 +242,15 @@ discard block |
||
238 | 242 | * @param bool $create |
239 | 243 | * @throws PhpfastcacheIOException |
240 | 244 | */ |
241 | - protected function htaccessGen($path, $create = true) |
|
242 | - { |
|
245 | + protected function htaccessGen($path, $create = true) { |
|
243 | 246 | if ($create === true) { |
244 | 247 | if (!\is_writable($path)) { |
245 | 248 | try { |
246 | 249 | if (!\chmod($path, 0777)) { |
247 | 250 | throw new PhpfastcacheIOException('Chmod failed on : ' . $path); |
248 | 251 | } |
249 | - } catch (PhpfastcacheIOException $e) { |
|
252 | + } |
|
253 | + catch (PhpfastcacheIOException $e) { |
|
250 | 254 | throw new PhpfastcacheIOException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!', 0, $e); |
251 | 255 | } |
252 | 256 | } |
@@ -351,7 +355,8 @@ discard block |
||
351 | 355 | if (!\rename($tmpFilename, $file)) { |
352 | 356 | throw new PhpfastcacheIOException(\sprintf('Failed to rename %s to %s', $tmpFilename, $file)); |
353 | 357 | } |
354 | - } else { |
|
358 | + } |
|
359 | + else { |
|
355 | 360 | $handle = \fopen($file, 'w+b'); |
356 | 361 | if (\is_resource($handle)) { |
357 | 362 | $octetWritten = \fwrite($handle, $data); |
@@ -66,8 +66,7 @@ discard block |
||
66 | 66 | * @throws PhpfastcacheDriverCheckException |
67 | 67 | * @throws PhpfastcacheDriverConnectException |
68 | 68 | */ |
69 | - public function __construct(ConfigurationOption $config, $instanceId) |
|
70 | - { |
|
69 | + public function __construct(ConfigurationOption $config, $instanceId) { |
|
71 | 70 | $this->setConfig($config); |
72 | 71 | $this->instanceId = $instanceId; |
73 | 72 | $this->IO = new DriverIO(); |
@@ -78,7 +77,8 @@ discard block |
||
78 | 77 | |
79 | 78 | try { |
80 | 79 | $this->driverConnect(); |
81 | - } catch (Exception $e) { |
|
80 | + } |
|
81 | + catch (Exception $e) { |
|
82 | 82 | throw new PhpfastcacheDriverConnectException( |
83 | 83 | sprintf( |
84 | 84 | self::DRIVER_CONNECT_FAILURE, |
@@ -143,7 +143,8 @@ discard block |
||
143 | 143 | * reuse it else set a new Date |
144 | 144 | */ |
145 | 145 | $wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = $item->getCreationDate() ?: new DateTime(); |
146 | - } else { |
|
146 | + } |
|
147 | + else { |
|
147 | 148 | $wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = null; |
148 | 149 | $wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = null; |
149 | 150 | } |
@@ -162,8 +163,7 @@ discard block |
||
162 | 163 | /** |
163 | 164 | * @param ConfigurationOption $config |
164 | 165 | */ |
165 | - public function setConfig(ConfigurationOption $config) |
|
166 | - { |
|
166 | + public function setConfig(ConfigurationOption $config) { |
|
167 | 167 | $this->config = $config; |
168 | 168 | } |
169 | 169 | |
@@ -171,8 +171,7 @@ discard block |
||
171 | 171 | * @param array $wrapper |
172 | 172 | * @return mixed |
173 | 173 | */ |
174 | - public function driverUnwrapData(array $wrapper) |
|
175 | - { |
|
174 | + public function driverUnwrapData(array $wrapper) { |
|
176 | 175 | return $wrapper[self::DRIVER_DATA_WRAPPER_INDEX]; |
177 | 176 | } |
178 | 177 | |
@@ -181,8 +180,7 @@ discard block |
||
181 | 180 | * @param array $wrapper |
182 | 181 | * @return DateTime |
183 | 182 | */ |
184 | - public function driverUnwrapEdate(array $wrapper) |
|
185 | - { |
|
183 | + public function driverUnwrapEdate(array $wrapper) { |
|
186 | 184 | return $wrapper[self::DRIVER_EDATE_WRAPPER_INDEX]; |
187 | 185 | } |
188 | 186 | |
@@ -190,8 +188,7 @@ discard block |
||
190 | 188 | * @param array $wrapper |
191 | 189 | * @return DateTime |
192 | 190 | */ |
193 | - public function driverUnwrapCdate(array $wrapper) |
|
194 | - { |
|
191 | + public function driverUnwrapCdate(array $wrapper) { |
|
195 | 192 | return $wrapper[self::DRIVER_CDATE_WRAPPER_INDEX]; |
196 | 193 | } |
197 | 194 | |
@@ -199,8 +196,7 @@ discard block |
||
199 | 196 | * @param array $wrapper |
200 | 197 | * @return DateTime |
201 | 198 | */ |
202 | - public function driverUnwrapMdate(array $wrapper) |
|
203 | - { |
|
199 | + public function driverUnwrapMdate(array $wrapper) { |
|
204 | 200 | return $wrapper[self::DRIVER_MDATE_WRAPPER_INDEX]; |
205 | 201 | } |
206 | 202 | |
@@ -232,8 +228,7 @@ discard block |
||
232 | 228 | * @param string|null $value |
233 | 229 | * @return mixed |
234 | 230 | */ |
235 | - protected function decode($value) |
|
236 | - { |
|
231 | + protected function decode($value) { |
|
237 | 232 | return \unserialize((string)$value, ['allowed_classes' => true]); |
238 | 233 | } |
239 | 234 |