Passed
Branch main (8837c4)
by Sílvio
14:13
created
src/CacheStore/ArrayCacheStore.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -13,117 +13,117 @@  discard block
 block discarded – undo
13 13
 class ArrayCacheStore implements CacheerInterface
14 14
 {
15 15
 
16
-  /**
17
-  * @param array $arrayStore
18
-  */
19
-  private array $arrayStore = [];
20
-
21
-  /**
22
-   * @var boolean
23
-   */
24
-  private bool $success = false;
25
-
26
-  /**
27
-   * @var string
28
-   */
29
-  private string $message = '';
30
-
31
-  /**
32
-   * @var ?CacheLogger
33
-   */
34
-  private ?CacheLogger $logger = null;
35
-
36
-  /**
37
-   * @var array<string, array<string,bool>>
38
-   */
39
-  private array $tags = [];
40
-
41
-  /**
42
-   * ArrayCacheStore constructor.
43
-   * 
44
-   * @param string $logPath
45
-   */
46
-  public function __construct(string $logPath)
47
-  {
16
+    /**
17
+     * @param array $arrayStore
18
+     */
19
+    private array $arrayStore = [];
20
+
21
+    /**
22
+     * @var boolean
23
+     */
24
+    private bool $success = false;
25
+
26
+    /**
27
+     * @var string
28
+     */
29
+    private string $message = '';
30
+
31
+    /**
32
+     * @var ?CacheLogger
33
+     */
34
+    private ?CacheLogger $logger = null;
35
+
36
+    /**
37
+     * @var array<string, array<string,bool>>
38
+     */
39
+    private array $tags = [];
40
+
41
+    /**
42
+     * ArrayCacheStore constructor.
43
+     * 
44
+     * @param string $logPath
45
+     */
46
+    public function __construct(string $logPath)
47
+    {
48 48
     $this->logger = new CacheLogger($logPath);
49
-  }
50
-
51
-  /**
52
-   * Appends data to an existing cache item.
53
-   * 
54
-   * @param string $cacheKey
55
-   * @param mixed  $cacheData
56
-   * @param string $namespace
57
-   * @return bool
58
-   */
59
-  public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
60
-  {
61
-      $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
62
-
63
-      if (!$this->has($cacheKey, $namespace)) {
64
-          $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false);
65
-          $this->logger->debug("{$this->getMessage()} from array driver.");
66
-          return false;
67
-      }
68
-
69
-      $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData);
70
-      $this->setMessage("Cache appended successfully", true);
71
-      return true;
72
-  }
73
-
74
-  /**
75
-   * Builds a unique key for the array store.
76
-   * 
77
-   * @param string $cacheKey
78
-   * @param string $namespace
79
-   * @return string
80
-   */
81
-  private function buildArrayKey(string $cacheKey, string $namespace = ''): string
82
-  {
49
+    }
50
+
51
+    /**
52
+     * Appends data to an existing cache item.
53
+     * 
54
+     * @param string $cacheKey
55
+     * @param mixed  $cacheData
56
+     * @param string $namespace
57
+     * @return bool
58
+     */
59
+    public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
60
+    {
61
+        $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
62
+
63
+        if (!$this->has($cacheKey, $namespace)) {
64
+            $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false);
65
+            $this->logger->debug("{$this->getMessage()} from array driver.");
66
+            return false;
67
+        }
68
+
69
+        $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData);
70
+        $this->setMessage("Cache appended successfully", true);
71
+        return true;
72
+    }
73
+
74
+    /**
75
+     * Builds a unique key for the array store.
76
+     * 
77
+     * @param string $cacheKey
78
+     * @param string $namespace
79
+     * @return string
80
+     */
81
+    private function buildArrayKey(string $cacheKey, string $namespace = ''): string
82
+    {
83 83
     return !empty($namespace) ? ($namespace . ':' . $cacheKey) : $cacheKey;
84
-  }
85
-
86
-  /**
87
-   * Clears a specific cache item.
88
-   * 
89
-   * @param string $cacheKey
90
-   * @param string $namespace
91
-   * @return void
92
-   */
93
-  public function clearCache(string $cacheKey, string $namespace = ''): void
94
-  {
84
+    }
85
+
86
+    /**
87
+     * Clears a specific cache item.
88
+     * 
89
+     * @param string $cacheKey
90
+     * @param string $namespace
91
+     * @return void
92
+     */
93
+    public function clearCache(string $cacheKey, string $namespace = ''): void
94
+    {
95 95
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
96 96
     unset($this->arrayStore[$arrayStoreKey]);
97 97
     $this->setMessage("Cache cleared successfully", true);
98 98
     $this->logger->debug("{$this->getMessage()} from array driver.");
99
-  }
100
-
101
-  /**
102
-   * Decrements a cache item by a specified amount.
103
-   * 
104
-   * @param string $cacheKey
105
-   * @param int $amount
106
-   * @param string $namespace
107
-   * @return bool
108
-   */
109
-  public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool
110
-  {
99
+    }
100
+
101
+    /**
102
+     * Decrements a cache item by a specified amount.
103
+     * 
104
+     * @param string $cacheKey
105
+     * @param int $amount
106
+     * @param string $namespace
107
+     * @return bool
108
+     */
109
+    public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool
110
+    {
111 111
     return $this->increment($cacheKey, ($amount * -1), $namespace);
112
-  }
113
-
114
-  /**
115
-   * Flushes all cache items.
116
-   * 
117
-   * @return void
118
-   */
119
-  public function flushCache(): void
120
-  {
112
+    }
113
+
114
+    /**
115
+     * Flushes all cache items.
116
+     * 
117
+     * @return void
118
+     */
119
+    public function flushCache(): void
120
+    {
121 121
     unset($this->arrayStore);
122 122
     $this->arrayStore = [];
123 123
     $this->tags = [];
124 124
     $this->setMessage("Cache flushed successfully", true);
125 125
     $this->logger->debug("{$this->getMessage()} from array driver.");
126
-  }
126
+    }
127 127
 
128 128
     /**
129 129
      * Stores a cache item permanently.
@@ -132,234 +132,234 @@  discard block
 block discarded – undo
132 132
      * @param mixed $cacheData
133 133
      * @return void
134 134
      */
135
-  public function forever(string $cacheKey, mixed $cacheData): void
136
-  {
135
+    public function forever(string $cacheKey, mixed $cacheData): void
136
+    {
137 137
     $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000);
138 138
     $this->setMessage($this->getMessage(), $this->isSuccess());
139
-  }
140
-
141
-  /**
142
-   * Retrieves a single cache item.
143
-   * 
144
-   * @param string $cacheKey
145
-   * @param string $namespace
146
-   * @param int|string $ttl
147
-   * @return mixed
148
-   */
149
-  public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
150
-  {
139
+    }
140
+
141
+    /**
142
+     * Retrieves a single cache item.
143
+     * 
144
+     * @param string $cacheKey
145
+     * @param string $namespace
146
+     * @param int|string $ttl
147
+     * @return mixed
148
+     */
149
+    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
150
+    {
151 151
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
152 152
 
153 153
     if (!$this->has($cacheKey, $namespace)) {
154
-      $this->handleCacheNotFound();
155
-      return false;
154
+        $this->handleCacheNotFound();
155
+        return false;
156 156
     }
157 157
 
158 158
     $cacheData = $this->arrayStore[$arrayStoreKey];
159 159
     if ($this->isExpired($cacheData)) {
160
-      $this->handleCacheExpired($arrayStoreKey);
161
-      return false;
160
+        $this->handleCacheExpired($arrayStoreKey);
161
+        return false;
162 162
     }
163 163
 
164 164
     $this->setMessage("Cache retrieved successfully", true);
165 165
     $this->logger->debug("{$this->getMessage()} from array driver.");
166 166
     return $this->serialize($cacheData['cacheData'], false);
167
-  }
168
-
169
-  /**
170
-   * Verify if the cache is expired.
171
-   * 
172
-   * @param array $cacheData
173
-   * @return bool
174
-   */
175
-  private function isExpired(array $cacheData): bool
176
-  {
167
+    }
168
+
169
+    /**
170
+     * Verify if the cache is expired.
171
+     * 
172
+     * @param array $cacheData
173
+     * @return bool
174
+     */
175
+    private function isExpired(array $cacheData): bool
176
+    {
177 177
     $expirationTime = $cacheData['expirationTime'] ?? 0;
178 178
     $now = time();
179 179
     return $expirationTime !== 0 && $now >= $expirationTime;
180
-  }
181
-
182
-  /**
183
-   * Handles the case when cache data is not found.
184
-   * 
185
-   * @return void
186
-   */
187
-  private function handleCacheNotFound(): void
188
-  {
180
+    }
181
+
182
+    /**
183
+     * Handles the case when cache data is not found.
184
+     * 
185
+     * @return void
186
+     */
187
+    private function handleCacheNotFound(): void
188
+    {
189 189
     $this->setMessage("cacheData not found, does not exists or expired", false);
190 190
     $this->logger->debug("{$this->getMessage()} from array driver.");
191
-  }
192
-
193
-  /**
194
-   * Handles the case when cache data has expired.
195
-   * 
196
-   * @param string $arrayStoreKey
197
-   * @return void
198
-   */
199
-  private function handleCacheExpired(string $arrayStoreKey): void
200
-  {
191
+    }
192
+
193
+    /**
194
+     * Handles the case when cache data has expired.
195
+     * 
196
+     * @param string $arrayStoreKey
197
+     * @return void
198
+     */
199
+    private function handleCacheExpired(string $arrayStoreKey): void
200
+    {
201 201
     $parts = explode(':', $arrayStoreKey, 2);
202 202
     if (count($parts) === 2) {
203
-      list($np, $key) = $parts;
203
+        list($np, $key) = $parts;
204 204
     } else {
205
-      $np = '';
206
-      $key = $arrayStoreKey;
205
+        $np = '';
206
+        $key = $arrayStoreKey;
207 207
     }
208 208
     $this->clearCache($key, $np);
209 209
     $this->setMessage("cacheKey: {$key} has expired.", false);
210 210
     $this->logger->debug("{$this->getMessage()} from array driver.");
211
-  }
212
-
213
-  /**
214
-   * Gets all items in a specific namespace.
215
-   * 
216
-   * @param string $namespace
217
-   * @return array
218
-   */
219
-  public function getAll(string $namespace = ''): array
220
-  {
211
+    }
212
+
213
+    /**
214
+     * Gets all items in a specific namespace.
215
+     * 
216
+     * @param string $namespace
217
+     * @return array
218
+     */
219
+    public function getAll(string $namespace = ''): array
220
+    {
221 221
     $results = [];
222 222
     foreach ($this->arrayStore as $key => $data) {
223
-      if (str_starts_with($key, $namespace . ':') || empty($namespace)) {
223
+        if (str_starts_with($key, $namespace . ':') || empty($namespace)) {
224 224
         $results[$key] = $this->serialize($data['cacheData'], false);
225
-      }
225
+        }
226 226
     }
227 227
     return $results;
228
-  }
229
-
230
-  /**
231
-   * Retrieves multiple cache items by their keys.
232
-   * 
233
-   * @param array $cacheKeys
234
-   * @param string $namespace
235
-   * @param string|int $ttl
236
-   * @return array
237
-   */
238
-  public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
239
-  {
228
+    }
229
+
230
+    /**
231
+     * Retrieves multiple cache items by their keys.
232
+     * 
233
+     * @param array $cacheKeys
234
+     * @param string $namespace
235
+     * @param string|int $ttl
236
+     * @return array
237
+     */
238
+    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
239
+    {
240 240
     $results = [];
241 241
     foreach ($cacheKeys as $cacheKey) {
242
-      $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl);
242
+        $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl);
243 243
     }
244 244
     return $results;
245
-  }
246
-
247
-  /**
248
-   * Checks if a cache item exists.
249
-   * 
250
-   * @param string $cacheKey
251
-   * @param string $namespace
252
-   * @return bool
253
-   */
254
-  public function has(string $cacheKey, string $namespace = ''): bool
255
-  {
245
+    }
246
+
247
+    /**
248
+     * Checks if a cache item exists.
249
+     * 
250
+     * @param string $cacheKey
251
+     * @param string $namespace
252
+     * @return bool
253
+     */
254
+    public function has(string $cacheKey, string $namespace = ''): bool
255
+    {
256 256
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
257 257
     $exists = isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime'];
258 258
 
259 259
     $this->setMessage(
260
-      $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!",
261
-      $exists
260
+        $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!",
261
+        $exists
262 262
     );
263 263
     $this->logger->debug("{$this->getMessage()} from array driver.");
264 264
 
265 265
     return $exists;
266
-  }
267
-
268
-  /**
269
-   * Increments a cache item by a specified amount.
270
-   * 
271
-   * @param string $cacheKey
272
-   * @param int $amount
273
-   * @param string $namespace
274
-   * @return bool
275
-   */
276
-  public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool
277
-  {
266
+    }
267
+
268
+    /**
269
+     * Increments a cache item by a specified amount.
270
+     * 
271
+     * @param string $cacheKey
272
+     * @param int $amount
273
+     * @param string $namespace
274
+     * @return bool
275
+     */
276
+    public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool
277
+    {
278 278
     $cacheData = $this->getCache($cacheKey, $namespace);
279 279
 
280 280
     if(!empty($cacheData) && is_numeric($cacheData)) {
281
-      $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
282
-      $this->setMessage($this->getMessage(), $this->isSuccess());
283
-      return true;
281
+        $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
282
+        $this->setMessage($this->getMessage(), $this->isSuccess());
283
+        return true;
284 284
     }
285 285
 
286 286
     return false;
287
-  }
288
-
289
-  /**
290
-   * Checks if the operation was successful.
291
-   * 
292
-   * @return boolean
293
-   */
294
-  public function isSuccess(): bool
295
-  {
287
+    }
288
+
289
+    /**
290
+     * Checks if the operation was successful.
291
+     * 
292
+     * @return boolean
293
+     */
294
+    public function isSuccess(): bool
295
+    {
296 296
     return $this->success;
297
-  }
298
-
299
-  /**
300
-   * Gets the last message.
301
-   * 
302
-   * @return string
303
-   */
304
-  public function getMessage(): string
305
-  {
297
+    }
298
+
299
+    /**
300
+     * Gets the last message.
301
+     * 
302
+     * @return string
303
+     */
304
+    public function getMessage(): string
305
+    {
306 306
     return $this->message;
307
-  }
308
-
309
-  /**
310
-   * Stores an item in the cache with a specific TTL.
311
-   * 
312
-   * @param string $cacheKey
313
-   * @param mixed $cacheData
314
-   * @param string $namespace
315
-   * @param int|string $ttl
316
-   * @return bool
317
-   */
318
-  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
319
-  {
307
+    }
308
+
309
+    /**
310
+     * Stores an item in the cache with a specific TTL.
311
+     * 
312
+     * @param string $cacheKey
313
+     * @param mixed $cacheData
314
+     * @param string $namespace
315
+     * @param int|string $ttl
316
+     * @return bool
317
+     */
318
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
319
+    {
320 320
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
321 321
 
322 322
     $this->arrayStore[$arrayStoreKey] = [
323
-      'cacheData' => serialize($cacheData),
324
-      'expirationTime' => time() + $ttl
323
+        'cacheData' => serialize($cacheData),
324
+        'expirationTime' => time() + $ttl
325 325
     ];
326 326
 
327 327
     $this->setMessage("Cache stored successfully", true);
328 328
     $this->logger->debug("{$this->getMessage()} from Array driver.");
329 329
     return true;
330
-  }
331
-
332
-  /**
333
-   * Stores multiple items in the cache in batches.
334
-   * 
335
-   * @param array $items
336
-   * @param string $namespace
337
-   * @param int $batchSize
338
-   * @return void
339
-   */
340
-  public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
341
-  {
330
+    }
331
+
332
+    /**
333
+     * Stores multiple items in the cache in batches.
334
+     * 
335
+     * @param array $items
336
+     * @param string $namespace
337
+     * @param int $batchSize
338
+     * @return void
339
+     */
340
+    public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
341
+    {
342 342
     $chunks = array_chunk($items, $batchSize, true);
343 343
 
344 344
     foreach ($chunks as $chunk) {
345
-      foreach ($chunk as $key => $data) {
346
-          $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
345
+        foreach ($chunk as $key => $data) {
346
+            $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
347
+        }
347 348
         }
348
-      }
349 349
     $this->setMessage("{$this->getMessage()}", $this->isSuccess());
350 350
     $this->logger->debug("{$this->getMessage()} from Array driver.");
351
-  }
352
-
353
-  /**
354
-   * Renews the expiration time of a cache item.
355
-   * 
356
-   * @param string $cacheKey
357
-   * @param string|int $ttl
358
-   * @param string $namespace
359
-   * @return void
360
-   */
361
-  public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
362
-  {
351
+    }
352
+
353
+    /**
354
+     * Renews the expiration time of a cache item.
355
+     * 
356
+     * @param string $cacheKey
357
+     * @param string|int $ttl
358
+     * @param string $namespace
359
+     * @return void
360
+     */
361
+    public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
362
+    {
363 363
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
364 364
 
365 365
     if (isset($this->arrayStore[$arrayStoreKey])) {
@@ -367,78 +367,78 @@  discard block
 block discarded – undo
367 367
         $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds;
368 368
         $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true);
369 369
         $this->logger->debug("{$this->getMessage()} from array driver.");
370
-      }
371
-  }
372
-
373
-  /**
374
-   * Sets a message and its success status.
375
-   * 
376
-   * @param string  $message
377
-   * @param boolean $success
378
-   * @return void
379
-   */
380
-  private function setMessage(string $message, bool $success): void
381
-  {
370
+        }
371
+    }
372
+
373
+    /**
374
+     * Sets a message and its success status.
375
+     * 
376
+     * @param string  $message
377
+     * @param boolean $success
378
+     * @return void
379
+     */
380
+    private function setMessage(string $message, bool $success): void
381
+    {
382 382
     $this->message = $message;
383 383
     $this->success = $success;
384
-  }
385
-
386
-  /**
387
-   * Serializes or unserializes data based on the flag.
388
-   * 
389
-   * @param mixed $data
390
-   * @param bool $serialize
391
-   * @return mixed
392
-   */
393
-  private function serialize(mixed $data, bool $serialize = true): mixed
394
-  {
384
+    }
385
+
386
+    /**
387
+     * Serializes or unserializes data based on the flag.
388
+     * 
389
+     * @param mixed $data
390
+     * @param bool $serialize
391
+     * @return mixed
392
+     */
393
+    private function serialize(mixed $data, bool $serialize = true): mixed
394
+    {
395 395
     return $serialize ? serialize($data) : unserialize($data);
396
-  }
397
-
398
-  /**
399
-   * Associates one or more keys to a tag.
400
-   *
401
-   * @param string $tag
402
-   * @param string ...$keys
403
-   * @return bool
404
-   */
405
-  public function tag(string $tag, string ...$keys): bool
406
-  {
396
+    }
397
+
398
+    /**
399
+     * Associates one or more keys to a tag.
400
+     *
401
+     * @param string $tag
402
+     * @param string ...$keys
403
+     * @return bool
404
+     */
405
+    public function tag(string $tag, string ...$keys): bool
406
+    {
407 407
     if (!isset($this->tags[$tag])) {
408
-      $this->tags[$tag] = [];
408
+        $this->tags[$tag] = [];
409 409
     }
410 410
     foreach ($keys as $key) {
411
-      // Accept either raw key or "namespace:key"
412
-      $arrayStoreKey = (str_contains($key, ':')) ? $key : $this->buildArrayKey($key, '');
413
-      $this->tags[$tag][$arrayStoreKey] = true;
411
+        // Accept either raw key or "namespace:key"
412
+        $arrayStoreKey = (str_contains($key, ':')) ? $key : $this->buildArrayKey($key, '');
413
+        $this->tags[$tag][$arrayStoreKey] = true;
414 414
     }
415 415
     $this->setMessage("Tagged successfully", true);
416 416
     $this->logger?->debug("{$this->getMessage()} from array driver.");
417 417
     return true;
418
-  }
419
-
420
-  /**
421
-   * Flushes all keys associated with a tag.
422
-   *
423
-   * @param string $tag
424
-   * @return void
425
-   */
426
-  public function flushTag(string $tag): void
427
-  {
418
+    }
419
+
420
+    /**
421
+     * Flushes all keys associated with a tag.
422
+     *
423
+     * @param string $tag
424
+     * @return void
425
+     */
426
+    public function flushTag(string $tag): void
427
+    {
428 428
     $keys = array_keys($this->tags[$tag] ?? []);
429 429
     foreach ($keys as $arrayStoreKey) {
430
-      // Recover original key/namespace combination
431
-      $parts = explode(':', $arrayStoreKey, 2);
432
-      if (count($parts) === 2) {
430
+        // Recover original key/namespace combination
431
+        $parts = explode(':', $arrayStoreKey, 2);
432
+        if (count($parts) === 2) {
433 433
         [$np, $key] = $parts;
434
-      } else {
434
+        } else {
435 435
         $np = '';
436 436
         $key = $arrayStoreKey;
437
-      }
438
-      $this->clearCache($key, $np);
437
+        }
438
+        $this->clearCache($key, $np);
439 439
     }
440 440
     unset($this->tags[$tag]);
441 441
     $this->setMessage("Tag flushed successfully", true);
442 442
     $this->logger?->debug("{$this->getMessage()} from array driver.");
443
-  }
443
+    }
444 444
 }
Please login to merge, or discard this patch.
src/Interface/CacheerInterface.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @param string|int $ttl Lifetime in seconds (default: 3600)
53 53
      * @return mixed Returns the cached data or null if not found
54 54
      */
55
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600);
55
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600);
56 56
 
57 57
     /**
58 58
      * Retrieves multiple cache items by their keys.
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      * @param string|int $ttl Lifetime in seconds (default: 3600)
63 63
      * @return CacheDataFormatter|mixed Returns a formatter with the retrieved items
64 64
      */
65
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600);
65
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600);
66 66
 
67 67
     /**
68 68
      * Checks if a cache item exists.
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @param string|int $ttl Lifetime in seconds (default: 3600)
83 83
      * @return bool True on success, false on failure
84 84
      */
85
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600);
85
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600);
86 86
 
87 87
     /**
88 88
      * Stores multiple items in the cache.
Please login to merge, or discard this patch.
src/Interface/CacheReadStoreInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * @param string|int $ttl
13 13
      * @return mixed
14 14
      */
15
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600);
15
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600);
16 16
 
17 17
     /**
18 18
      * Retrieves multiple cache items by their keys.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * @param string|int $ttl
23 23
      * @return mixed
24 24
      */
25
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600);
25
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600);
26 26
 
27 27
     /**
28 28
      * Gets all items in a specific namespace.
Please login to merge, or discard this patch.
src/Interface/CacheWriteStoreInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param int|string $ttl
40 40
      * @return mixed
41 41
      */
42
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600);
42
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600);
43 43
 
44 44
     /**
45 45
      * Stores multiple items in the cache.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      * @param string $namespace
60 60
      * @return mixed
61 61
      */
62
-    public function renewCache(string $cacheKey, int|string $ttl, string $namespace = '');
62
+    public function renewCache(string $cacheKey, int | string $ttl, string $namespace = '');
63 63
 
64 64
     /**
65 65
      * Retrieves the last operation message.
Please login to merge, or discard this patch.
src/CacheStore/RedisCacheStore.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
         $this->redis = RedisCacheManager::connect();
62 62
         $logger = new CacheLogger($logPath);
63 63
 
64
-        $namespace = !empty($options['namespace']) ? (string) $options['namespace'] : '';
64
+        $namespace = !empty($options['namespace']) ? (string)$options['namespace'] : '';
65 65
         $defaultTTL = null;
66 66
 
67 67
         if (!empty($options['expirationTime'])) {
68
-            $defaultTTL = (int) CacheFileHelper::convertExpirationToSeconds((string) $options['expirationTime']);
68
+            $defaultTTL = (int)CacheFileHelper::convertExpirationToSeconds((string)$options['expirationTime']);
69 69
         }
70 70
 
71 71
         $this->keyspace = new RedisKeyspace($namespace, $defaultTTL);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 
75 75
         // Auto-flush support
76 76
         $lastFlushFile = FlushHelper::pathFor(CacheStoreType::REDIS, $namespace ?: 'default');
77
-        $this->flusher = new GenericFlusher($lastFlushFile, function () {
77
+        $this->flusher = new GenericFlusher($lastFlushFile, function() {
78 78
             $this->flushCache();
79 79
         });
80 80
         $this->flusher->handleAutoFlush($options);
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function flushTag(string $tag): void
170 170
     {
171
-        $this->tagIndex->flush($tag, function (string $cacheKey, string $namespace): void {
171
+        $this->tagIndex->flush($tag, function(string $cacheKey, string $namespace): void {
172 172
             $this->clearCache($cacheKey, $namespace);
173 173
         });
174 174
     }
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      * @param string|int $ttl
182 182
      * @return mixed
183 183
      */
184
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
184
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed
185 185
     {
186 186
         $fullCacheKey = $this->buildKey($cacheKey, $namespace);
187 187
         $cacheData = $this->redis->get($fullCacheKey);
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      * @param string|int $ttl
235 235
      * @return array
236 236
      */
237
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
237
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array
238 238
     {
239 239
         $results = [];
240 240
         foreach ($cacheKeys as $cacheKey) {
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
      * @param string|int|null $ttl
314 314
      * @return Status|null
315 315
      */
316
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): ?Status
316
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): ?Status
317 317
     {
318 318
         $cacheFullKey = $this->buildKey($cacheKey, $namespace);
319 319
         $serializedData = CacheRedisHelper::serialize($cacheData);
320 320
 
321 321
         $ttlToUse = $this->keyspace->resolveTTL($ttl);
322 322
 
323
-        $result = $ttlToUse ? $this->redis->setex($cacheFullKey, (int) $ttlToUse, $serializedData)
323
+        $result = $ttlToUse ? $this->redis->setex($cacheFullKey, (int)$ttlToUse, $serializedData)
324 324
                             : $this->redis->set($cacheFullKey, $serializedData);
325 325
 
326 326
         if ($result) {
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
     public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
344 344
     {
345 345
         $writer = new RedisBatchWriter($batchSize);
346
-        $writer->write($items, $namespace, function (string $cacheKey, mixed $cacheData, string $ns): void {
346
+        $writer->write($items, $namespace, function(string $cacheKey, mixed $cacheData, string $ns): void {
347 347
             $this->putCache($cacheKey, $cacheData, $ns);
348 348
         });
349 349
     }
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
      * @return void
358 358
      * @throws CacheRedisException
359 359
      */
360
-    public function renewCache(string $cacheKey, string|int $ttl, string $namespace = ''): void
360
+    public function renewCache(string $cacheKey, string | int $ttl, string $namespace = ''): void
361 361
     {
362 362
         $cacheFullKey = $this->buildKey($cacheKey, $namespace);
363 363
         $dump = $this->getDump($cacheFullKey);
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * @return bool
386 386
      * @throws CacheRedisException
387 387
      */
388
-    private function restoreKey(string $fullKey, string|int $ttl, mixed $dump): bool
388
+    private function restoreKey(string $fullKey, string | int $ttl, mixed $dump): bool
389 389
     {
390 390
         try {
391 391
             $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE');
Please login to merge, or discard this patch.
src/CacheStore/Support/RedisKeyspace.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,18 +53,18 @@
 block discarded – undo
53 53
      * 
54 54
      * @return int|null
55 55
      */
56
-    public function resolveTTL(string|int|null $ttl): ?int
56
+    public function resolveTTL(string | int | null $ttl): ?int
57 57
     {
58 58
         $ttlToUse = $ttl;
59 59
 
60
-        if ($this->defaultTTL !== null && ($ttl === null || (int) $ttl === 3600)) {
60
+        if ($this->defaultTTL !== null && ($ttl === null || (int)$ttl === 3600)) {
61 61
             $ttlToUse = $this->defaultTTL;
62 62
         }
63 63
 
64 64
         if (is_string($ttlToUse)) {
65
-            $ttlToUse = (int) CacheFileHelper::convertExpirationToSeconds($ttlToUse);
65
+            $ttlToUse = (int)CacheFileHelper::convertExpirationToSeconds($ttlToUse);
66 66
         }
67 67
 
68
-        return $ttlToUse === null ? null : (int) $ttlToUse;
68
+        return $ttlToUse === null ? null : (int)$ttlToUse;
69 69
     }
70 70
 }
Please login to merge, or discard this patch.
src/CacheStore/Support/RedisTagIndex.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
         $setKey = $this->keyspace->tagKey($tag);
40 40
         $added = 0;
41 41
         foreach ($keys as $key) {
42
-            $added += (int) $this->redis->sadd($setKey, [$key]);
42
+            $added += (int)$this->redis->sadd($setKey, [$key]);
43 43
         }
44 44
 
45 45
         $this->status->record('Tagged successfully', true);
Please login to merge, or discard this patch.
src/CacheStore/DatabaseCacheStore.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
         MigrationManager::migrate($pdo, $table);
65 65
 
66 66
         if (!empty($options['expirationTime'])) {
67
-            $this->defaultTTL = (int) CacheFileHelper::convertExpirationToSeconds((string) $options['expirationTime']);
67
+            $this->defaultTTL = (int)CacheFileHelper::convertExpirationToSeconds((string)$options['expirationTime']);
68 68
         }
69 69
 
70 70
         $lastFlushFile = FlushHelper::pathFor(CacheStoreType::DATABASE, $table);
71
-        $this->flusher = new GenericFlusher($lastFlushFile, function () {
71
+        $this->flusher = new GenericFlusher($lastFlushFile, function() {
72 72
             $this->flushCache();
73 73
         });
74 74
         $this->flusher->handleAutoFlush($options);
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
     public function clearCache(string $cacheKey, string $namespace = ''): void
107 107
     {
108 108
         $data = $this->cacheRepository->clear($cacheKey, $namespace);
109
-        if($data) {
109
+        if ($data) {
110 110
             $this->setMessage("Cache deleted successfully!", true);
111 111
         } else {
112 112
             $this->setMessage("Cache does not exists!", false);
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function flushCache(): void
124 124
     {
125
-        if($this->cacheRepository->flush()){
125
+        if ($this->cacheRepository->flush()) {
126 126
             $this->setMessage("Flush finished successfully", true);
127 127
         } else {
128 128
             $this->setMessage("Something went wrong. Please, try again.", false);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param string|int $ttl
192 192
      * @return mixed
193 193
      */
194
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
194
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed
195 195
     {
196 196
         $cacheData = $this->retrieveCache($cacheKey, $namespace);
197 197
         if ($cacheData) {
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @param string|int $ttl
232 232
      * @return array
233 233
      */
234
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
234
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array
235 235
     {
236 236
         $cacheData = [];
237 237
         foreach ($cacheKeys as $cacheKey) {
@@ -321,17 +321,17 @@  discard block
 block discarded – undo
321 321
      * @param string|int $ttl
322 322
      * @return bool
323 323
      */
324
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool
324
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): bool
325 325
     {
326 326
         $ttlToUse = $ttl;
327 327
         if ($this->defaultTTL !== null && ($ttl === null || (int)$ttl === 3600)) {
328 328
             $ttlToUse = $this->defaultTTL;
329 329
         }
330 330
         if (is_string($ttlToUse)) {
331
-            $ttlToUse = (int) CacheFileHelper::convertExpirationToSeconds($ttlToUse);
331
+            $ttlToUse = (int)CacheFileHelper::convertExpirationToSeconds($ttlToUse);
332 332
         }
333 333
 
334
-        if($this->storeCache($cacheKey, $cacheData, $namespace, $ttlToUse)){
334
+        if ($this->storeCache($cacheKey, $cacheData, $namespace, $ttlToUse)) {
335 335
             $this->logger->debug("{$this->getMessage()} from database driver.");
336 336
             return true;
337 337
         }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
      */
367 367
     private function processBatchItems(array $batchItems, string $namespace): void
368 368
     {
369
-        foreach($batchItems as $item) {
369
+        foreach ($batchItems as $item) {
370 370
             CacheDatabaseHelper::validateCacheItem($item);
371 371
             $cacheKey = $item['cacheKey'];
372 372
             $cacheData = $item['cacheData'];
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
      * @param string $namespace
384 384
      * @return bool
385 385
      */
386
-    private function renew(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): bool
386
+    private function renew(string $cacheKey, string | int $ttl = 3600, string $namespace = ''): bool
387 387
     {
388 388
         $cacheData = $this->getCache($cacheKey, $namespace);
389 389
         if ($cacheData) {
@@ -431,10 +431,10 @@  discard block
 block discarded – undo
431 431
      * @param string|int $ttl
432 432
      * @return bool
433 433
      */
434
-    private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool
434
+    private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): bool
435 435
     {
436 436
         $data = $this->cacheRepository->store($cacheKey, $cacheData, $namespace, $ttl);
437
-        if($data) {
437
+        if ($data) {
438 438
             $this->setMessage("Cache Stored Successfully", true);
439 439
             return true;
440 440
         }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     private function updateCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
454 454
     {
455 455
         $data = $this->cacheRepository->update($cacheKey, $cacheData, $namespace);
456
-        if($data) {
456
+        if ($data) {
457 457
             $this->setMessage("Cache updated successfully.", true);
458 458
             return true;
459 459
         }
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/GenericFlusher.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         if (!isset($options['flushAfter'])) {
51 51
             return;
52 52
         }
53
-        $this->scheduleFlush((string) $options['flushAfter']);
53
+        $this->scheduleFlush((string)$options['flushAfter']);
54 54
     }
55 55
 
56 56
     /**
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
      */
60 60
     private function scheduleFlush(string $flushAfter): void
61 61
     {
62
-        $flushAfterSeconds = (int) CacheFileHelper::convertExpirationToSeconds($flushAfter);
62
+        $flushAfterSeconds = (int)CacheFileHelper::convertExpirationToSeconds($flushAfter);
63 63
 
64 64
         if (!file_exists($this->lastFlushTimeFile)) {
65 65
             $this->writeTimestamp(time());
66 66
             return;
67 67
         }
68 68
 
69
-        $lastFlushTime = (int) @file_get_contents($this->lastFlushTimeFile);
69
+        $lastFlushTime = (int)@file_get_contents($this->lastFlushTimeFile);
70 70
 
71 71
         if ((time() - $lastFlushTime) >= $flushAfterSeconds) {
72 72
             $this->flushCache();
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     private function writeTimestamp(int $timestamp): void
84 84
     {
85
-        $result = @file_put_contents($this->lastFlushTimeFile, (string) $timestamp, LOCK_EX);
85
+        $result = @file_put_contents($this->lastFlushTimeFile, (string)$timestamp, LOCK_EX);
86 86
         if ($result === false) {
87 87
             throw new \RuntimeException("Failed to write flush timestamp to {$this->lastFlushTimeFile}");
88 88
         }
Please login to merge, or discard this patch.