Passed
Branch main (f01baa)
by Sílvio
03:03
created
src/CacheStore/ArrayCacheStore.php 1 patch
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -13,111 +13,111 @@  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
-   * ArrayCacheStore constructor.
38
-   * 
39
-   * @param string $logPath
40
-   */
41
-  public function __construct(string $logPath)
42
-  {
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
+     * ArrayCacheStore constructor.
38
+     * 
39
+     * @param string $logPath
40
+     */
41
+    public function __construct(string $logPath)
42
+    {
43 43
     $this->logger = new CacheLogger($logPath);
44
-  }
45
-
46
-  /**
47
-   * Appends data to an existing cache item.
48
-   * 
49
-   * @param string $cacheKey
50
-   * @param mixed  $cacheData
51
-   * @param string $namespace
52
-   * @return bool
53
-   */
54
-  public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
55
-  {
56
-      $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
57
-
58
-      if (!$this->has($cacheKey, $namespace)) {
59
-          $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false);
60
-          $this->logger->debug("{$this->getMessage()} from array driver.");
61
-          return false;
62
-      }
63
-
64
-      $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData);
65
-      $this->setMessage("Cache appended successfully", true);
66
-      return true;
67
-  }
68
-
69
-  /**
70
-   * Builds a unique key for the array store.
71
-   * 
72
-   * @param string $cacheKey
73
-   * @param string $namespace
74
-   * @return string
75
-   */
76
-  private function buildArrayKey(string $cacheKey, string $namespace = ''): string
77
-  {
44
+    }
45
+
46
+    /**
47
+     * Appends data to an existing cache item.
48
+     * 
49
+     * @param string $cacheKey
50
+     * @param mixed  $cacheData
51
+     * @param string $namespace
52
+     * @return bool
53
+     */
54
+    public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
55
+    {
56
+        $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
57
+
58
+        if (!$this->has($cacheKey, $namespace)) {
59
+            $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false);
60
+            $this->logger->debug("{$this->getMessage()} from array driver.");
61
+            return false;
62
+        }
63
+
64
+        $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData);
65
+        $this->setMessage("Cache appended successfully", true);
66
+        return true;
67
+    }
68
+
69
+    /**
70
+     * Builds a unique key for the array store.
71
+     * 
72
+     * @param string $cacheKey
73
+     * @param string $namespace
74
+     * @return string
75
+     */
76
+    private function buildArrayKey(string $cacheKey, string $namespace = ''): string
77
+    {
78 78
     return !empty($namespace) ? ($namespace . ':' . $cacheKey) : $cacheKey;
79
-  }
80
-
81
-  /**
82
-   * Clears a specific cache item.
83
-   * 
84
-   * @param string $cacheKey
85
-   * @param string $namespace
86
-   * @return void
87
-   */
88
-  public function clearCache(string $cacheKey, string $namespace = ''): void
89
-  {
79
+    }
80
+
81
+    /**
82
+     * Clears a specific cache item.
83
+     * 
84
+     * @param string $cacheKey
85
+     * @param string $namespace
86
+     * @return void
87
+     */
88
+    public function clearCache(string $cacheKey, string $namespace = ''): void
89
+    {
90 90
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
91 91
     unset($this->arrayStore[$arrayStoreKey]);
92 92
     $this->setMessage("Cache cleared successfully", true);
93 93
     $this->logger->debug("{$this->getMessage()} from array driver.");
94
-  }
95
-
96
-  /**
97
-   * Decrements a cache item by a specified amount.
98
-   * 
99
-   * @param string $cacheKey
100
-   * @param int $amount
101
-   * @param string $namespace
102
-   * @return bool
103
-   */
104
-  public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool
105
-  {
94
+    }
95
+
96
+    /**
97
+     * Decrements a cache item by a specified amount.
98
+     * 
99
+     * @param string $cacheKey
100
+     * @param int $amount
101
+     * @param string $namespace
102
+     * @return bool
103
+     */
104
+    public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool
105
+    {
106 106
     return $this->increment($cacheKey, ($amount * -1), $namespace);
107
-  }
108
-
109
-  /**
110
-   * Flushes all cache items.
111
-   * 
112
-   * @return void
113
-   */
114
-  public function flushCache(): void
115
-  {
107
+    }
108
+
109
+    /**
110
+     * Flushes all cache items.
111
+     * 
112
+     * @return void
113
+     */
114
+    public function flushCache(): void
115
+    {
116 116
     unset($this->arrayStore);
117 117
     $this->arrayStore = [];
118 118
     $this->setMessage("Cache flushed successfully", true);
119 119
     $this->logger->debug("{$this->getMessage()} from array driver.");
120
-  }
120
+    }
121 121
 
122 122
     /**
123 123
      * Stores a cache item permanently.
@@ -126,226 +126,226 @@  discard block
 block discarded – undo
126 126
      * @param mixed $cacheData
127 127
      * @return void
128 128
      */
129
-  public function forever(string $cacheKey, mixed $cacheData): void
130
-  {
129
+    public function forever(string $cacheKey, mixed $cacheData): void
130
+    {
131 131
     $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000);
132 132
     $this->setMessage($this->getMessage(), $this->isSuccess());
133
-  }
134
-
135
-  /**
136
-   * Retrieves a single cache item.
137
-   * 
138
-   * @param string $cacheKey
139
-   * @param string $namespace
140
-   * @param int|string $ttl
141
-   * @return mixed
142
-   */
143
-  public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
144
-  {
133
+    }
134
+
135
+    /**
136
+     * Retrieves a single cache item.
137
+     * 
138
+     * @param string $cacheKey
139
+     * @param string $namespace
140
+     * @param int|string $ttl
141
+     * @return mixed
142
+     */
143
+    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
144
+    {
145 145
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
146 146
 
147 147
     if (!$this->has($cacheKey, $namespace)) {
148
-      $this->handleCacheNotFound();
149
-      return false;
148
+        $this->handleCacheNotFound();
149
+        return false;
150 150
     }
151 151
 
152 152
     $cacheData = $this->arrayStore[$arrayStoreKey];
153 153
     if ($this->isExpired($cacheData)) {
154
-      $this->handleCacheExpired($arrayStoreKey);
155
-      return false;
154
+        $this->handleCacheExpired($arrayStoreKey);
155
+        return false;
156 156
     }
157 157
 
158 158
     $this->setMessage("Cache retrieved successfully", true);
159 159
     $this->logger->debug("{$this->getMessage()} from array driver.");
160 160
     return $this->serialize($cacheData['cacheData'], false);
161
-  }
162
-
163
-  /**
164
-   * Verify if the cache is expired.
165
-   * 
166
-   * @param array $cacheData
167
-   * @return bool
168
-   */
169
-  private function isExpired(array $cacheData): bool
170
-  {
161
+    }
162
+
163
+    /**
164
+     * Verify if the cache is expired.
165
+     * 
166
+     * @param array $cacheData
167
+     * @return bool
168
+     */
169
+    private function isExpired(array $cacheData): bool
170
+    {
171 171
     $expirationTime = $cacheData['expirationTime'] ?? 0;
172 172
     $now = time();
173 173
     return $expirationTime !== 0 && $now >= $expirationTime;
174
-  }
175
-
176
-  /**
177
-   * Handles the case when cache data is not found.
178
-   * 
179
-   * @return void
180
-   */
181
-  private function handleCacheNotFound(): void
182
-  {
174
+    }
175
+
176
+    /**
177
+     * Handles the case when cache data is not found.
178
+     * 
179
+     * @return void
180
+     */
181
+    private function handleCacheNotFound(): void
182
+    {
183 183
     $this->setMessage("cacheData not found, does not exists or expired", false);
184 184
     $this->logger->debug("{$this->getMessage()} from array driver.");
185
-  }
186
-
187
-  /**
188
-   * Handles the case when cache data has expired.
189
-   * 
190
-   * @param string $arrayStoreKey
191
-   * @return void
192
-   */
193
-  private function handleCacheExpired(string $arrayStoreKey): void
194
-  {
185
+    }
186
+
187
+    /**
188
+     * Handles the case when cache data has expired.
189
+     * 
190
+     * @param string $arrayStoreKey
191
+     * @return void
192
+     */
193
+    private function handleCacheExpired(string $arrayStoreKey): void
194
+    {
195 195
     $parts = explode(':', $arrayStoreKey, 2);
196 196
     if (count($parts) === 2) {
197
-      list($np, $key) = $parts;
197
+        list($np, $key) = $parts;
198 198
     } else {
199
-      $np = '';
200
-      $key = $arrayStoreKey;
199
+        $np = '';
200
+        $key = $arrayStoreKey;
201 201
     }
202 202
     $this->clearCache($key, $np);
203 203
     $this->setMessage("cacheKey: {$key} has expired.", false);
204 204
     $this->logger->debug("{$this->getMessage()} from array driver.");
205
-  }
206
-
207
-  /**
208
-   * Gets all items in a specific namespace.
209
-   * 
210
-   * @param string $namespace
211
-   * @return array
212
-   */
213
-  public function getAll(string $namespace = ''): array
214
-  {
205
+    }
206
+
207
+    /**
208
+     * Gets all items in a specific namespace.
209
+     * 
210
+     * @param string $namespace
211
+     * @return array
212
+     */
213
+    public function getAll(string $namespace = ''): array
214
+    {
215 215
     $results = [];
216 216
     foreach ($this->arrayStore as $key => $data) {
217
-      if (str_starts_with($key, $namespace . ':') || empty($namespace)) {
217
+        if (str_starts_with($key, $namespace . ':') || empty($namespace)) {
218 218
         $results[$key] = $this->serialize($data['cacheData'], false);
219
-      }
219
+        }
220 220
     }
221 221
     return $results;
222
-  }
223
-
224
-  /**
225
-   * Retrieves multiple cache items by their keys.
226
-   * 
227
-   * @param array $cacheKeys
228
-   * @param string $namespace
229
-   * @param string|int $ttl
230
-   * @return array
231
-   */
232
-  public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
233
-  {
222
+    }
223
+
224
+    /**
225
+     * Retrieves multiple cache items by their keys.
226
+     * 
227
+     * @param array $cacheKeys
228
+     * @param string $namespace
229
+     * @param string|int $ttl
230
+     * @return array
231
+     */
232
+    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
233
+    {
234 234
     $results = [];
235 235
     foreach ($cacheKeys as $cacheKey) {
236
-      $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl);
236
+        $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl);
237 237
     }
238 238
     return $results;
239
-  }
240
-
241
-  /**
242
-   * Checks if a cache item exists.
243
-   * 
244
-   * @param string $cacheKey
245
-   * @param string $namespace
246
-   * @return bool
247
-   */
248
-  public function has(string $cacheKey, string $namespace = ''): bool
249
-  {
239
+    }
240
+
241
+    /**
242
+     * Checks if a cache item exists.
243
+     * 
244
+     * @param string $cacheKey
245
+     * @param string $namespace
246
+     * @return bool
247
+     */
248
+    public function has(string $cacheKey, string $namespace = ''): bool
249
+    {
250 250
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
251 251
     return isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime'];
252
-  }
253
-
254
-  /**
255
-   * Increments a cache item by a specified amount.
256
-   * 
257
-   * @param string $cacheKey
258
-   * @param int $amount
259
-   * @param string $namespace
260
-   * @return bool
261
-   */
262
-  public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool
263
-  {
252
+    }
253
+
254
+    /**
255
+     * Increments a cache item by a specified amount.
256
+     * 
257
+     * @param string $cacheKey
258
+     * @param int $amount
259
+     * @param string $namespace
260
+     * @return bool
261
+     */
262
+    public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool
263
+    {
264 264
     $cacheData = $this->getCache($cacheKey, $namespace);
265 265
 
266 266
     if(!empty($cacheData) && is_numeric($cacheData)) {
267
-      $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
268
-      $this->setMessage($this->getMessage(), $this->isSuccess());
269
-      return true;
267
+        $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
268
+        $this->setMessage($this->getMessage(), $this->isSuccess());
269
+        return true;
270 270
     }
271 271
 
272 272
     return false;
273
-  }
274
-
275
-  /**
276
-   * Checks if the operation was successful.
277
-   * 
278
-   * @return boolean
279
-   */
280
-  public function isSuccess(): bool
281
-  {
273
+    }
274
+
275
+    /**
276
+     * Checks if the operation was successful.
277
+     * 
278
+     * @return boolean
279
+     */
280
+    public function isSuccess(): bool
281
+    {
282 282
     return $this->success;
283
-  }
284
-
285
-  /**
286
-   * Gets the last message.
287
-   * 
288
-   * @return string
289
-   */
290
-  public function getMessage(): string
291
-  {
283
+    }
284
+
285
+    /**
286
+     * Gets the last message.
287
+     * 
288
+     * @return string
289
+     */
290
+    public function getMessage(): string
291
+    {
292 292
     return $this->message;
293
-  }
294
-
295
-  /**
296
-   * Stores an item in the cache with a specific TTL.
297
-   * 
298
-   * @param string $cacheKey
299
-   * @param mixed $cacheData
300
-   * @param string $namespace
301
-   * @param int|string $ttl
302
-   * @return bool
303
-   */
304
-  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
305
-  {
293
+    }
294
+
295
+    /**
296
+     * Stores an item in the cache with a specific TTL.
297
+     * 
298
+     * @param string $cacheKey
299
+     * @param mixed $cacheData
300
+     * @param string $namespace
301
+     * @param int|string $ttl
302
+     * @return bool
303
+     */
304
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
305
+    {
306 306
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
307 307
 
308 308
     $this->arrayStore[$arrayStoreKey] = [
309
-      'cacheData' => serialize($cacheData),
310
-      'expirationTime' => time() + $ttl
309
+        'cacheData' => serialize($cacheData),
310
+        'expirationTime' => time() + $ttl
311 311
     ];
312 312
 
313 313
     $this->setMessage("Cache stored successfully", true);
314 314
     $this->logger->debug("{$this->getMessage()} from Array driver.");
315 315
     return true;
316
-  }
317
-
318
-  /**
319
-   * Stores multiple items in the cache in batches.
320
-   * 
321
-   * @param array $items
322
-   * @param string $namespace
323
-   * @param int $batchSize
324
-   * @return void
325
-   */
326
-  public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
327
-  {
316
+    }
317
+
318
+    /**
319
+     * Stores multiple items in the cache in batches.
320
+     * 
321
+     * @param array $items
322
+     * @param string $namespace
323
+     * @param int $batchSize
324
+     * @return void
325
+     */
326
+    public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
327
+    {
328 328
     $chunks = array_chunk($items, $batchSize, true);
329 329
 
330 330
     foreach ($chunks as $chunk) {
331
-      foreach ($chunk as $key => $data) {
332
-          $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
331
+        foreach ($chunk as $key => $data) {
332
+            $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
333
+        }
333 334
         }
334
-      }
335 335
     $this->setMessage("{$this->getMessage()}", $this->isSuccess());
336 336
     $this->logger->debug("{$this->getMessage()} from Array driver.");
337
-  }
338
-
339
-  /**
340
-   * Renews the expiration time of a cache item.
341
-   * 
342
-   * @param string $cacheKey
343
-   * @param string|int $ttl
344
-   * @param string $namespace
345
-   * @return void
346
-   */
347
-  public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
348
-  {
337
+    }
338
+
339
+    /**
340
+     * Renews the expiration time of a cache item.
341
+     * 
342
+     * @param string $cacheKey
343
+     * @param string|int $ttl
344
+     * @param string $namespace
345
+     * @return void
346
+     */
347
+    public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
348
+    {
349 349
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
350 350
 
351 351
     if (isset($this->arrayStore[$arrayStoreKey])) {
@@ -353,31 +353,31 @@  discard block
 block discarded – undo
353 353
         $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds;
354 354
         $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true);
355 355
         $this->logger->debug("{$this->getMessage()} from array driver.");
356
-      }
357
-  }
358
-
359
-  /**
360
-   * Sets a message and its success status.
361
-   * 
362
-   * @param string  $message
363
-   * @param boolean $success
364
-   * @return void
365
-   */
366
-  private function setMessage(string $message, bool $success): void
367
-  {
356
+        }
357
+    }
358
+
359
+    /**
360
+     * Sets a message and its success status.
361
+     * 
362
+     * @param string  $message
363
+     * @param boolean $success
364
+     * @return void
365
+     */
366
+    private function setMessage(string $message, bool $success): void
367
+    {
368 368
     $this->message = $message;
369 369
     $this->success = $success;
370
-  }
371
-
372
-  /**
373
-   * Serializes or unserializes data based on the flag.
374
-   * 
375
-   * @param mixed $data
376
-   * @param bool $serialize
377
-   * @return mixed
378
-   */
379
-  private function serialize(mixed $data, bool $serialize = true): mixed
380
-  {
370
+    }
371
+
372
+    /**
373
+     * Serializes or unserializes data based on the flag.
374
+     * 
375
+     * @param mixed $data
376
+     * @param bool $serialize
377
+     * @return mixed
378
+     */
379
+    private function serialize(mixed $data, bool $serialize = true): mixed
380
+    {
381 381
     return $serialize ? serialize($data) : unserialize($data);
382
-  }
382
+    }
383 383
 }
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/FileCacheManager.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -53,18 +53,18 @@  discard block
 block discarded – undo
53 53
     }
54 54
 
55 55
     /**
56
-    * @param string $filename
57
-    * @return bool
58
-    */
56
+     * @param string $filename
57
+     * @return bool
58
+     */
59 59
     public function fileExists(string $filename): bool
60 60
     {
61 61
         return file_exists($filename);
62 62
     }
63 63
 
64 64
     /**
65
-    * @param string $filename
66
-    * @return void
67
-    */
65
+     * @param string $filename
66
+     * @return void
67
+     */
68 68
     public function removeFile(string $filename): void
69 69
     {
70 70
         if (file_exists($filename)) {
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
     }
74 74
 
75 75
     /**
76
-    * @param string $dir
77
-    * @return void
78
-    */
76
+     * @param string $dir
77
+     * @return void
78
+     */
79 79
     public function clearDirectory(string $dir): void
80 80
     {
81 81
         $iterator = new RecursiveIteratorIterator(
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/RedisCacheManager.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -14,42 +14,42 @@
 block discarded – undo
14 14
 class RedisCacheManager
15 15
 {
16 16
 
17
-  /** @var Predis\Client */
18
-  private static $redis;
19
-
20
-  /** @param string $namespace */
21
-  private static $namespace;
22
-
23
-  /**
24
-   * Connects to the Redis server using the configuration defined in REDIS_CONNECTION_CONFIG.
25
-   * 
26
-  * @return Client
27
-  */
28
-  public static function connect()
29
-  {
17
+    /** @var Predis\Client */
18
+    private static $redis;
19
+
20
+    /** @param string $namespace */
21
+    private static $namespace;
22
+
23
+    /**
24
+     * Connects to the Redis server using the configuration defined in REDIS_CONNECTION_CONFIG.
25
+     * 
26
+     * @return Client
27
+     */
28
+    public static function connect()
29
+    {
30 30
     Autoloader::register();
31 31
     self::$redis = new Client([
32
-      'scheme' => 'tcp',
33
-      'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'],
34
-      'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'],
35
-      'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'],
36
-      'database' => 0
32
+        'scheme' => 'tcp',
33
+        'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'],
34
+        'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'],
35
+        'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'],
36
+        'database' => 0
37 37
     ]);
38 38
     self::auth();
39 39
     self::$namespace = REDIS_CONNECTION_CONFIG['REDIS_NAMESPACE'] ?? 'Cache';
40 40
     return self::$redis;
41
-  }
42
-
43
-  /**
44
-  * Authenticates the Redis connection if a password is provided in the configuration.
45
-  *
46
-  * @return void
47
-  */
48
-  private static function auth(): void
49
-  {
41
+    }
42
+
43
+    /**
44
+     * Authenticates the Redis connection if a password is provided in the configuration.
45
+     *
46
+     * @return void
47
+     */
48
+    private static function auth(): void
49
+    {
50 50
     if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
51
-      self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
51
+        self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
52
+    }
52 53
     }
53
-  }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/FileCacheFlusher.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -13,18 +13,18 @@  discard block
 block discarded – undo
13 13
 class FileCacheFlusher
14 14
 {
15 15
     /**
16
-    * @var FileCacheManager
17
-    */
16
+     * @var FileCacheManager
17
+     */
18 18
     private FileCacheManager $fileManager;
19 19
 
20 20
     /**
21
-    * @var string $cacheDir
22
-    */
21
+     * @var string $cacheDir
22
+     */
23 23
     private string $cacheDir;
24 24
 
25 25
     /**
26
-    * @var string $lastFlushTimeFile
27
-    */
26
+     * @var string $lastFlushTimeFile
27
+     */
28 28
     private string $lastFlushTimeFile;
29 29
 
30 30
     /**
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
     }
42 42
 
43 43
     /**
44
-    * Flushes all cache items and updates the last flush timestamp.
45
-    *
46
-    * @return void
47
-    */
44
+     * Flushes all cache items and updates the last flush timestamp.
45
+     *
46
+     * @return void
47
+     */
48 48
     public function flushCache(): void
49 49
     {
50 50
         $this->fileManager->clearDirectory($this->cacheDir);
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
     }
53 53
 
54 54
     /**
55
-    * Handles the auto-flush functionality based on options.
56
-    *
57
-    * @param array $options
58
-    * @return void
59
-    */
55
+     * Handles the auto-flush functionality based on options.
56
+     *
57
+     * @param array $options
58
+     * @return void
59
+     */
60 60
     public function handleAutoFlush(array $options): void
61 61
     {
62 62
         if (isset($options['flushAfter'])) {
Please login to merge, or discard this patch.
src/Repositories/CacheDatabaseRepository.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
     }
61 61
 
62 62
     /**
63
-    * Retrieves cache data from the database.
64
-    * 
65
-    * @param string $cacheKey
66
-    * @param string $namespace
67
-    * @return mixed
63
+     * Retrieves cache data from the database.
64
+     * 
65
+     * @param string $cacheKey
66
+     * @param string $namespace
67
+     * @return mixed
68 68
      */
69 69
     public function retrieve(string $cacheKey, string $namespace = ''): mixed
70 70
     {
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
     }
110 110
 
111 111
     /**
112
-    * Get Update query based on the database driver.
113
-    *
114
-    * @return string
115
-    */
112
+     * Get Update query based on the database driver.
113
+     *
114
+     * @return string
115
+     */
116 116
     private function getUpdateQueryWithDriver(): string
117 117
     {
118 118
         $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
     }
124 124
 
125 125
     /**
126
-    * Get Delete query based on the database driver.
127
-    * 
128
-    * @return string
129
-    */
126
+     * Get Delete query based on the database driver.
127
+     * 
128
+     * @return string
129
+     */
130 130
     private function getDeleteQueryWithDriver(): string
131 131
     {
132 132
         $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
     }
138 138
 
139 139
     /**
140
-    * Updates an existing cache item in the database.
141
-    * 
142
-    * @param string $cacheKey
143
-    * @param mixed  $cacheData
144
-    * @param string $namespace
145
-    * @return bool
146
-    */
140
+     * Updates an existing cache item in the database.
141
+     * 
142
+     * @param string $cacheKey
143
+     * @param mixed  $cacheData
144
+     * @param string $namespace
145
+     * @return bool
146
+     */
147 147
     public function update(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
148 148
     {
149 149
         $query = $this->getUpdateQueryWithDriver();
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
     }
158 158
 
159 159
     /**
160
-    * Clears a specific cache item from the database.
161
-    * 
162
-    * @param string $cacheKey
163
-    * @param string $namespace
164
-    * @return bool
165
-    */
160
+     * Clears a specific cache item from the database.
161
+     * 
162
+     * @param string $cacheKey
163
+     * @param string $namespace
164
+     * @return bool
165
+     */
166 166
     public function clear(string $cacheKey, string $namespace = ''): bool
167 167
     {
168 168
         $query = $this->getDeleteQueryWithDriver();
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
     }
176 176
 
177 177
     /**
178
-    * Gets the query to renew the expiration time of a cache item based on the database driver.
179
-    *  
180
-    * @return string
181
-    */
178
+     * Gets the query to renew the expiration time of a cache item based on the database driver.
179
+     *  
180
+     * @return string
181
+     */
182 182
     private function getRenewExpirationQueryWithDriver(): string
183 183
     {
184 184
         $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
     }
194 194
 
195 195
     /**
196
-    * Checks if a cache item is valid based on its key, namespace, and current time.
197
-    * 
198
-    * @param string $cacheKey
199
-    * @param string $namespace
200
-    * @param string $currentTime
201
-    * @return bool
202
-    */
196
+     * Checks if a cache item is valid based on its key, namespace, and current time.
197
+     * 
198
+     * @param string $cacheKey
199
+     * @param string $namespace
200
+     * @param string $currentTime
201
+     * @return bool
202
+     */
203 203
     private function hasValidCache(string $cacheKey, string $namespace, string $currentTime): bool
204 204
     {
205 205
         $stmt = $this->connection->prepare(
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
     }
216 216
 
217 217
     /**
218
-    * Renews the expiration time of a cache item.
219
-    * 
220
-    * @param string $cacheKey
221
-    * @param string|int $ttl
222
-    * @param string $namespace
223
-    * @return bool
224
-    */
218
+     * Renews the expiration time of a cache item.
219
+     * 
220
+     * @param string $cacheKey
221
+     * @param string|int $ttl
222
+     * @param string $namespace
223
+     * @return bool
224
+     */
225 225
     public function renew(string $cacheKey, string|int $ttl, string $namespace = ''): bool
226 226
     {
227 227
         $currentTime = date('Y-m-d H:i:s');
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
     }
242 242
 
243 243
     /**
244
-    * Flushes all cache items from the database.
245
-    * 
246
-    * @return bool
247
-    */
244
+     * Flushes all cache items from the database.
245
+     * 
246
+     * @return bool
247
+     */
248 248
     public function flush(): bool
249 249
     {
250 250
         return $this->connection->exec("DELETE FROM cacheer_table") !== false;
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
     }
264 264
 
265 265
     /**
266
-    * Gets the current date and time based on the database driver.
267
-    * 
268
-    * @param string $driver
269
-    * @return string
270
-    */
266
+     * Gets the current date and time based on the database driver.
267
+     * 
268
+     * @param string $driver
269
+     * @return string
270
+     */
271 271
     private function getCurrentDateTime(string $driver): string
272 272
     {
273 273
         return ($driver === 'sqlite') ? "DATETIME('now', 'localtime')" : "NOW()";
Please login to merge, or discard this patch.
src/Config/Option/Builder/OptionBuilder.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@
 block discarded – undo
12 12
 class OptionBuilder
13 13
 {
14 14
   
15
-  /**
16
-  * Creates a FileOptionBuilder instance for file-based cache options.
17
-  *
18
-  * @return FileOptionBuilder
19
-  */
20
-  public static function forFile(): FileOptionBuilder
21
-  {
15
+    /**
16
+     * Creates a FileOptionBuilder instance for file-based cache options.
17
+     *
18
+     * @return FileOptionBuilder
19
+     */
20
+    public static function forFile(): FileOptionBuilder
21
+    {
22 22
     return new FileOptionBuilder();
23
-  }
23
+    }
24 24
 }
Please login to merge, or discard this patch.
src/Service/CacheRetriever.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@
 block discarded – undo
16 16
 class CacheRetriever
17 17
 {
18 18
     /**
19
-    * @var Cacheer
20
-    */
19
+     * @var Cacheer
20
+     */
21 21
     private Cacheer $cacheer;
22 22
 
23 23
     /**
24
-    * CacheRetriever constructor.
25
-    *
26
-    * @param Cacheer $cacheer
27
-    */
24
+     * CacheRetriever constructor.
25
+     *
26
+     * @param Cacheer $cacheer
27
+     */
28 28
     public function __construct(Cacheer $cacheer)
29 29
     {
30 30
         $this->cacheer = $cacheer;
Please login to merge, or discard this patch.
src/Service/CacheMutator.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -13,29 +13,29 @@  discard block
 block discarded – undo
13 13
 class CacheMutator
14 14
 {
15 15
     /**
16
-    * @var Cacheer
17
-    */
16
+     * @var Cacheer
17
+     */
18 18
     private Cacheer $cacheer;
19 19
 
20 20
     /**
21
-    * CacheMutator constructor.
22
-    *
23
-    * @param Cacheer $cacheer
24
-    */
21
+     * CacheMutator constructor.
22
+     *
23
+     * @param Cacheer $cacheer
24
+     */
25 25
     public function __construct(Cacheer $cacheer)
26 26
     {
27 27
         $this->cacheer = $cacheer;
28 28
     }
29 29
 
30 30
     /**
31
-    * Adds a cache item if it does not already exist.
32
-    *
33
-    * @param string $cacheKey
34
-    * @param mixed $cacheData
35
-    * @param string $namespace
36
-    * @param int|string $ttl
37
-    * @return bool
38
-    */
31
+     * Adds a cache item if it does not already exist.
32
+     *
33
+     * @param string $cacheKey
34
+     * @param mixed $cacheData
35
+     * @param string $namespace
36
+     * @param int|string $ttl
37
+     * @return bool
38
+     */
39 39
     public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
40 40
     {
41 41
         if (!empty($this->cacheer->getCache($cacheKey, $namespace))) {
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
     }
50 50
 
51 51
     /**
52
-    * Appends data to an existing cache item.
53
-    *
54
-    * @param string $cacheKey
55
-    * @param mixed $cacheData
56
-    * @param string $namespace
57
-    * @return void
58
-    */
52
+     * Appends data to an existing cache item.
53
+     *
54
+     * @param string $cacheKey
55
+     * @param mixed $cacheData
56
+     * @param string $namespace
57
+     * @return void
58
+     */
59 59
     public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): void
60 60
     {
61 61
         $this->cacheer->cacheStore->appendCache($cacheKey, $cacheData, $namespace);
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
     }
64 64
 
65 65
     /**
66
-    * Clears a specific cache item.
67
-    *
68
-    * @param string $cacheKey
69
-    * @param string $namespace
70
-    * @return void
71
-    */
66
+     * Clears a specific cache item.
67
+     *
68
+     * @param string $cacheKey
69
+     * @param string $namespace
70
+     * @return void
71
+     */
72 72
     public function clearCache(string $cacheKey, string $namespace = ''): void
73 73
     {
74 74
         $this->cacheer->cacheStore->clearCache($cacheKey, $namespace);
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-    * Decrements a numeric cache item by a specified amount.
80
-    *
81
-    * @param string $cacheKey
82
-    * @param int $amount
83
-    * @param string $namespace
84
-    * @return bool
85
-    */
79
+     * Decrements a numeric cache item by a specified amount.
80
+     *
81
+     * @param string $cacheKey
82
+     * @param int $amount
83
+     * @param string $namespace
84
+     * @return bool
85
+     */
86 86
     public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool
87 87
     {
88 88
         return $this->increment($cacheKey, ($amount * -1), $namespace);
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
     }
103 103
 
104 104
     /**
105
-    * Flushes the entire cache.
106
-    *
107
-    * @return void
108
-    */
105
+     * Flushes the entire cache.
106
+     *
107
+     * @return void
108
+     */
109 109
     public function flushCache(): void
110 110
     {
111 111
         $this->cacheer->cacheStore->flushCache();
@@ -150,26 +150,26 @@  discard block
 block discarded – undo
150 150
     }
151 151
 
152 152
     /**
153
-    * Puts multiple cache items in a batch.
154
-    *
155
-    * @param array $items
156
-    * @param string $namespace
157
-    * @param int $batchSize
158
-    * @return void
159
-    */
153
+     * Puts multiple cache items in a batch.
154
+     *
155
+     * @param array $items
156
+     * @param string $namespace
157
+     * @param int $batchSize
158
+     * @return void
159
+     */
160 160
     public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
161 161
     {
162 162
         $this->cacheer->cacheStore->putMany($items, $namespace, $batchSize);
163 163
     }
164 164
 
165 165
     /**
166
-    * Renews the cache item with a new TTL.
167
-    *
168
-    * @param string $cacheKey
169
-    * @param int|string $ttl
170
-    * @param string $namespace
171
-    * @return void
172
-    */
166
+     * Renews the cache item with a new TTL.
167
+     *
168
+     * @param string $cacheKey
169
+     * @param int|string $ttl
170
+     * @param string $namespace
171
+     * @return void
172
+     */
173 173
     public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
174 174
     {
175 175
         $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace);
Please login to merge, or discard this patch.
src/Support/TimeBuilder.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -13,24 +13,24 @@  discard block
 block discarded – undo
13 13
 class TimeBuilder
14 14
 {
15 15
     
16
-  /** @param Closure $callback */
17
-  private Closure $callback;
16
+    /** @param Closure $callback */
17
+    private Closure $callback;
18 18
 
19
-  /** @var ?FileOptionBuilder */
20
-  private ?FileOptionBuilder $builder = null;
19
+    /** @var ?FileOptionBuilder */
20
+    private ?FileOptionBuilder $builder = null;
21 21
 
22
-  /**
23
-  * TimeBuilder constructor.
24
-  * @param Closure $callback
25
-  * @param FileOptionBuilder $builder
26
-  *
27
-  * @return void
28
-  */
29
-  public function __construct(Closure $callback, FileOptionBuilder $builder)
30
-  {
22
+    /**
23
+     * TimeBuilder constructor.
24
+     * @param Closure $callback
25
+     * @param FileOptionBuilder $builder
26
+     *
27
+     * @return void
28
+     */
29
+    public function __construct(Closure $callback, FileOptionBuilder $builder)
30
+    {
31 31
     $this->callback = $callback;
32 32
     $this->builder = $builder;
33
-  }
33
+    }
34 34
 
35 35
     /**
36 36
      * Sets the time in seconds.
@@ -38,10 +38,10 @@  discard block
 block discarded – undo
38 38
      * @param int $seconds
39 39
      * @return FileOptionBuilder|null
40 40
      */
41
-  public function second(int $seconds): ?FileOptionBuilder
42
-  {
41
+    public function second(int $seconds): ?FileOptionBuilder
42
+    {
43 43
     return $this->setTime($seconds, "seconds");
44
-  }
44
+    }
45 45
 
46 46
     /**
47 47
      * Sets the time in minutes.
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
      * @param int $minutes
50 50
      * @return FileOptionBuilder|null
51 51
      */
52
-  public function minute(int $minutes): ?FileOptionBuilder
53
-  {
52
+    public function minute(int $minutes): ?FileOptionBuilder
53
+    {
54 54
     return $this->setTime($minutes, "minutes");
55
-  }
55
+    }
56 56
 
57 57
     /**
58 58
      * Sets the time in hours.
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
      * @param int $hours
61 61
      * @return FileOptionBuilder|null
62 62
      */
63
-  public function hour(int $hours): ?FileOptionBuilder
64
-  {
63
+    public function hour(int $hours): ?FileOptionBuilder
64
+    {
65 65
     return $this->setTime($hours, "hours");
66
-  }
66
+    }
67 67
 
68 68
     /**
69 69
      * Sets the time in days.
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
      * @param int $days
72 72
      * @return FileOptionBuilder|null
73 73
      */
74
-  public function day(int $days): ?FileOptionBuilder
75
-  {
74
+    public function day(int $days): ?FileOptionBuilder
75
+    {
76 76
     return $this->setTime($days, "days");
77
-  }
77
+    }
78 78
 
79 79
     /**
80 80
      * Sets the time in weeks.
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
      * @param int $weeks
83 83
      * @return FileOptionBuilder|null
84 84
      */
85
-  public function week(int $weeks): ?FileOptionBuilder
86
-  {
85
+    public function week(int $weeks): ?FileOptionBuilder
86
+    {
87 87
     return $this->setTime($weeks, "weeks");
88
-  }
88
+    }
89 89
 
90 90
     /**
91 91
      * Sets the time in months.
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
      * @param int $months
94 94
      * @return FileOptionBuilder|null
95 95
      */
96
-  public function month(int $months): ?FileOptionBuilder
97
-  {
96
+    public function month(int $months): ?FileOptionBuilder
97
+    {
98 98
     return $this->setTime($months, "months");
99
-  }
99
+    }
100 100
 
101 101
 
102 102
     /**
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
      * @param string $unit
107 107
      * @return FileOptionBuilder|null
108 108
      */
109
-  private function setTime(int $value, string $unit): ?FileOptionBuilder
110
-  {
111
-   ($this->callback)("{$value} {$unit}");
109
+    private function setTime(int $value, string $unit): ?FileOptionBuilder
110
+    {
111
+    ($this->callback)("{$value} {$unit}");
112 112
     return $this->builder;
113
-  }
113
+    }
114 114
 
115 115
 }
Please login to merge, or discard this patch.