Passed
Branch main (6fd149)
by Sílvio
02:57
created
src/CacheStore/Support/DatabaseTtlResolver.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,18 +24,18 @@
 block discarded – undo
24 24
      * @param string|int|null $ttl
25 25
      * @return int
26 26
      */
27
-    public function resolve(string|int|null $ttl): int
27
+    public function resolve(string | int | null $ttl): int
28 28
     {
29 29
         $ttlToUse = $ttl;
30 30
 
31
-        if ($this->defaultTTL !== null && ($ttl === null || (int) $ttl === 3600)) {
31
+        if ($this->defaultTTL !== null && ($ttl === null || (int)$ttl === 3600)) {
32 32
             $ttlToUse = $this->defaultTTL;
33 33
         }
34 34
 
35 35
         if (is_string($ttlToUse)) {
36
-            $ttlToUse = (int) CacheFileHelper::convertExpirationToSeconds($ttlToUse);
36
+            $ttlToUse = (int)CacheFileHelper::convertExpirationToSeconds($ttlToUse);
37 37
         }
38 38
 
39
-        return (int) $ttlToUse;
39
+        return (int)$ttlToUse;
40 40
     }
41 41
 }
Please login to merge, or discard this patch.
src/CacheStore/DatabaseCacheStore.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
         $defaultTTL = null;
74 74
         if (!empty($options['expirationTime'])) {
75
-            $defaultTTL = (int) CacheFileHelper::convertExpirationToSeconds((string) $options['expirationTime']);
75
+            $defaultTTL = (int)CacheFileHelper::convertExpirationToSeconds((string)$options['expirationTime']);
76 76
         }
77 77
 
78 78
         $this->ttlResolver = new DatabaseTtlResolver($defaultTTL);
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $this->tagIndex = new DatabaseCacheTagIndex($this->cacheRepository, $this->status);
81 81
 
82 82
         $lastFlushFile = FlushHelper::pathFor(CacheStoreType::DATABASE, $table);
83
-        $this->flusher = new GenericFlusher($lastFlushFile, function () {
83
+        $this->flusher = new GenericFlusher($lastFlushFile, function() {
84 84
             $this->flushCache();
85 85
         });
86 86
         $this->flusher->handleAutoFlush($options);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function flushTag(string $tag): void
159 159
     {
160
-        $this->tagIndex->flush($tag, function (string $cacheKey, string $namespace): void {
160
+        $this->tagIndex->flush($tag, function(string $cacheKey, string $namespace): void {
161 161
             $this->clearCache($cacheKey, $namespace);
162 162
         });
163 163
     }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      * @param string|int $ttl
171 171
      * @return mixed
172 172
      */
173
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
173
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed
174 174
     {
175 175
         $cacheData = $this->cacheRepository->retrieve($cacheKey, $namespace);
176 176
         if ($cacheData !== null) {
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      * @param string|int $ttl
207 207
      * @return array
208 208
      */
209
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
209
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array
210 210
     {
211 211
         $cacheData = [];
212 212
         foreach ($cacheKeys as $cacheKey) {
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
     public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
276 276
     {
277 277
         $writer = $batchSize === 100 ? $this->batchWriter : new DatabaseBatchWriter($batchSize);
278
-        $writer->write($items, $namespace, function (string $cacheKey, mixed $cacheData, string $namespace): void {
278
+        $writer->write($items, $namespace, function(string $cacheKey, mixed $cacheData, string $namespace): void {
279 279
             $this->putCache($cacheKey, $cacheData, $namespace);
280 280
         });
281 281
     }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      * @param string|int $ttl
290 290
      * @return bool
291 291
      */
292
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool
292
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): bool
293 293
     {
294 294
         $ttlToUse = $this->ttlResolver->resolve($ttl);
295 295
         $stored = $this->cacheRepository->store($cacheKey, $cacheData, $namespace, $ttlToUse);
Please login to merge, or discard this patch.
src/CacheStore/ArrayCacheStore.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
      */
44 44
     private ArrayCacheTagIndex $tagIndex;
45 45
 
46
-  /**
47
-   * ArrayCacheStore constructor.
48
-   * 
49
-   * @param string $logPath
50
-   */
46
+    /**
47
+     * ArrayCacheStore constructor.
48
+     * 
49
+     * @param string $logPath
50
+     */
51 51
     public function __construct(string $logPath)
52 52
     {
53 53
         $logger = new CacheLogger($logPath);
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
         $this->tagIndex = new ArrayCacheTagIndex($this->keyspace, $this->status);
58 58
     }
59 59
 
60
-  /**
61
-   * Appends data to an existing cache item.
62
-   * 
63
-   * @param string $cacheKey
64
-   * @param mixed  $cacheData
65
-   * @param string $namespace
66
-   * @return bool
67
-   */
60
+    /**
61
+     * Appends data to an existing cache item.
62
+     * 
63
+     * @param string $cacheKey
64
+     * @param mixed  $cacheData
65
+     * @param string $namespace
66
+     * @return bool
67
+     */
68 68
     public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
69 69
     {
70 70
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
         return true;
81 81
     }
82 82
 
83
-  /**
84
-   * Clears a specific cache item.
85
-   * 
86
-   * @param string $cacheKey
87
-   * @param string $namespace
88
-   * @return void
89
-   */
83
+    /**
84
+     * Clears a specific cache item.
85
+     * 
86
+     * @param string $cacheKey
87
+     * @param string $namespace
88
+     * @return void
89
+     */
90 90
     public function clearCache(string $cacheKey, string $namespace = ''): void
91 91
     {
92 92
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
         $this->status->record("Cache cleared successfully", true);
95 95
     }
96 96
 
97
-  /**
98
-   * Decrements a cache item by a specified amount.
99
-   * 
100
-   * @param string $cacheKey
101
-   * @param int $amount
102
-   * @param string $namespace
103
-   * @return bool
104
-   */
97
+    /**
98
+     * Decrements a cache item by a specified amount.
99
+     * 
100
+     * @param string $cacheKey
101
+     * @param int $amount
102
+     * @param string $namespace
103
+     * @return bool
104
+     */
105 105
     public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool
106 106
     {
107 107
         return $this->increment($cacheKey, ($amount * -1), $namespace);
108 108
     }
109 109
 
110
-  /**
111
-   * Flushes all cache items.
112
-   * 
113
-   * @return void
114
-   */
110
+    /**
111
+     * Flushes all cache items.
112
+     * 
113
+     * @return void
114
+     */
115 115
     public function flushCache(): void
116 116
     {
117 117
         $this->arrayStore = [];
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
         $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000);
132 132
     }
133 133
 
134
-  /**
135
-   * Retrieves a single cache item.
136
-   * 
137
-   * @param string $cacheKey
138
-   * @param string $namespace
139
-   * @param int|string $ttl
140
-   * @return mixed
141
-   */
134
+    /**
135
+     * Retrieves a single cache item.
136
+     * 
137
+     * @param string $cacheKey
138
+     * @param string $namespace
139
+     * @param int|string $ttl
140
+     * @return mixed
141
+     */
142 142
     public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
143 143
     {
144 144
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
         return $this->codec->decode($cacheData['cacheData']);
160 160
     }
161 161
 
162
-  /**
163
-   * Gets all items in a specific namespace.
164
-   * 
165
-   * @param string $namespace
166
-   * @return array
167
-   */
162
+    /**
163
+     * Gets all items in a specific namespace.
164
+     * 
165
+     * @param string $namespace
166
+     * @return array
167
+     */
168 168
     public function getAll(string $namespace = ''): array
169 169
     {
170 170
         $results = [];
@@ -176,14 +176,14 @@  discard block
 block discarded – undo
176 176
         return $results;
177 177
     }
178 178
 
179
-  /**
180
-   * Retrieves multiple cache items by their keys.
181
-   * 
182
-   * @param array $cacheKeys
183
-   * @param string $namespace
184
-   * @param string|int $ttl
185
-   * @return array
186
-   */
179
+    /**
180
+     * Retrieves multiple cache items by their keys.
181
+     * 
182
+     * @param array $cacheKeys
183
+     * @param string $namespace
184
+     * @param string|int $ttl
185
+     * @return array
186
+     */
187 187
     public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
188 188
     {
189 189
         $results = [];
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
         return $results;
194 194
     }
195 195
 
196
-  /**
197
-   * Checks if a cache item exists.
198
-   * 
199
-   * @param string $cacheKey
200
-   * @param string $namespace
201
-   * @return bool
202
-   */
196
+    /**
197
+     * Checks if a cache item exists.
198
+     * 
199
+     * @param string $cacheKey
200
+     * @param string $namespace
201
+     * @return bool
202
+     */
203 203
     public function has(string $cacheKey, string $namespace = ''): bool
204 204
     {
205 205
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
@@ -214,14 +214,14 @@  discard block
 block discarded – undo
214 214
         return $exists;
215 215
     }
216 216
 
217
-  /**
218
-   * Increments a cache item by a specified amount.
219
-   * 
220
-   * @param string $cacheKey
221
-   * @param int $amount
222
-   * @param string $namespace
223
-   * @return bool
224
-   */
217
+    /**
218
+     * Increments a cache item by a specified amount.
219
+     * 
220
+     * @param string $cacheKey
221
+     * @param int $amount
222
+     * @param string $namespace
223
+     * @return bool
224
+     */
225 225
     public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool
226 226
     {
227 227
         $cacheData = $this->getCache($cacheKey, $namespace);
@@ -234,35 +234,35 @@  discard block
 block discarded – undo
234 234
         return false;
235 235
     }
236 236
 
237
-  /**
238
-   * Checks if the operation was successful.
239
-   * 
240
-   * @return boolean
241
-   */
237
+    /**
238
+     * Checks if the operation was successful.
239
+     * 
240
+     * @return boolean
241
+     */
242 242
     public function isSuccess(): bool
243 243
     {
244 244
         return $this->status->isSuccess();
245 245
     }
246 246
 
247
-  /**
248
-   * Gets the last message.
249
-   * 
250
-   * @return string
251
-   */
247
+    /**
248
+     * Gets the last message.
249
+     * 
250
+     * @return string
251
+     */
252 252
     public function getMessage(): string
253 253
     {
254 254
         return $this->status->getMessage();
255 255
     }
256 256
 
257
-  /**
258
-   * Stores an item in the cache with a specific TTL.
259
-   * 
260
-   * @param string $cacheKey
261
-   * @param mixed $cacheData
262
-   * @param string $namespace
263
-   * @param int|string $ttl
264
-   * @return bool
265
-   */
257
+    /**
258
+     * Stores an item in the cache with a specific TTL.
259
+     * 
260
+     * @param string $cacheKey
261
+     * @param mixed $cacheData
262
+     * @param string $namespace
263
+     * @param int|string $ttl
264
+     * @return bool
265
+     */
266 266
     public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
267 267
     {
268 268
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
         return true;
277 277
     }
278 278
 
279
-  /**
280
-   * Stores multiple items in the cache in batches.
281
-   * 
282
-   * @param array $items
283
-   * @param string $namespace
284
-   * @param int $batchSize
285
-   * @return void
286
-   */
279
+    /**
280
+     * Stores multiple items in the cache in batches.
281
+     * 
282
+     * @param array $items
283
+     * @param string $namespace
284
+     * @param int $batchSize
285
+     * @return void
286
+     */
287 287
     public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
288 288
     {
289 289
         $writer = new ArrayCacheBatchWriter($batchSize);
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
         $this->status->record($this->getMessage(), $this->isSuccess());
295 295
     }
296 296
 
297
-  /**
298
-   * Renews the expiration time of a cache item.
299
-   * 
300
-   * @param string $cacheKey
301
-   * @param string|int $ttl
302
-   * @param string $namespace
303
-   * @return void
304
-   */
297
+    /**
298
+     * Renews the expiration time of a cache item.
299
+     * 
300
+     * @param string $cacheKey
301
+     * @param string|int $ttl
302
+     * @param string $namespace
303
+     * @return void
304
+     */
305 305
     public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
306 306
     {
307 307
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
@@ -313,24 +313,24 @@  discard block
 block discarded – undo
313 313
         }
314 314
     }
315 315
 
316
-  /**
317
-   * Associates one or more keys to a tag.
318
-   *
319
-   * @param string $tag
320
-   * @param string ...$keys
321
-   * @return bool
322
-   */
316
+    /**
317
+     * Associates one or more keys to a tag.
318
+     *
319
+     * @param string $tag
320
+     * @param string ...$keys
321
+     * @return bool
322
+     */
323 323
     public function tag(string $tag, string ...$keys): bool
324 324
     {
325 325
         return $this->tagIndex->tag($tag, ...$keys);
326 326
     }
327 327
 
328
-  /**
329
-   * Flushes all keys associated with a tag.
330
-   *
331
-   * @param string $tag
332
-   * @return void
333
-   */
328
+    /**
329
+     * Flushes all keys associated with a tag.
330
+     *
331
+     * @param string $tag
332
+     * @return void
333
+     */
334 334
     public function flushTag(string $tag): void
335 335
     {
336 336
         $this->tagIndex->flush($tag, function (string $cacheKey, string $namespace): void {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
    * @param int|string $ttl
140 140
    * @return mixed
141 141
    */
142
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
142
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed
143 143
     {
144 144
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
145 145
         $cacheData = $this->arrayStore[$arrayStoreKey] ?? null;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
    * @param string|int $ttl
185 185
    * @return array
186 186
    */
187
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
187
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array
188 188
     {
189 189
         $results = [];
190 190
         foreach ($cacheKeys as $cacheKey) {
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         $cacheData = $this->getCache($cacheKey, $namespace);
228 228
 
229 229
         if (!empty($cacheData) && is_numeric($cacheData)) {
230
-            $this->putCache($cacheKey, (int) ($cacheData + $amount), $namespace);
230
+            $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
231 231
             return true;
232 232
         }
233 233
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
    * @param int|string $ttl
264 264
    * @return bool
265 265
    */
266
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
266
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600): bool
267 267
     {
268 268
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
269 269
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
     public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
288 288
     {
289 289
         $writer = new ArrayCacheBatchWriter($batchSize);
290
-        $writer->write($items, $namespace, function (string $cacheKey, mixed $cacheData, string $namespace): void {
290
+        $writer->write($items, $namespace, function(string $cacheKey, mixed $cacheData, string $namespace): void {
291 291
             $this->putCache($cacheKey, $cacheData, $namespace);
292 292
         });
293 293
 
@@ -302,12 +302,12 @@  discard block
 block discarded – undo
302 302
    * @param string $namespace
303 303
    * @return void
304 304
    */
305
-    public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
305
+    public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = ''): void
306 306
     {
307 307
         $arrayStoreKey = $this->keyspace->build($cacheKey, $namespace);
308 308
 
309 309
         if (isset($this->arrayStore[$arrayStoreKey])) {
310
-            $ttlSeconds = is_numeric($ttl) ? (int) $ttl : strtotime($ttl) - time();
310
+            $ttlSeconds = is_numeric($ttl) ? (int)$ttl : strtotime($ttl) - time();
311 311
             $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds;
312 312
             $this->status->record("cacheKey: {$cacheKey} renewed successfully", true);
313 313
         }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
    */
334 334
     public function flushTag(string $tag): void
335 335
     {
336
-        $this->tagIndex->flush($tag, function (string $cacheKey, string $namespace): void {
336
+        $this->tagIndex->flush($tag, function(string $cacheKey, string $namespace): void {
337 337
             $this->clearCache($cacheKey, $namespace);
338 338
         });
339 339
     }
Please login to merge, or discard this patch.
src/CacheStore/FileCacheStore.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -45,13 +45,13 @@
 block discarded – undo
45 45
     private OperationStatus $status;
46 46
 
47 47
     /**
48
-    * @var FileCacheManager
49
-    */
48
+     * @var FileCacheManager
49
+     */
50 50
     private FileCacheManager $fileManager;
51 51
 
52 52
     /**
53
-    * @var FileCacheFlusher
54
-    */
53
+     * @var FileCacheFlusher
54
+     */
55 55
     private FileCacheFlusher $flusher;
56 56
 
57 57
     /**
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         $this->flusher = new FileCacheFlusher($this->fileManager, $this->cacheDir);
79 79
         $this->tagIndex = new FileCacheTagIndex($this->fileManager, $this->cacheDir, $this->status);
80 80
         if (isset($options['expirationTime'])) {
81
-            $this->defaultTTL = (int) CacheFileHelper::convertExpirationToSeconds((string) $options['expirationTime']);
81
+            $this->defaultTTL = (int)CacheFileHelper::convertExpirationToSeconds((string)$options['expirationTime']);
82 82
         }
83 83
         $this->flusher->handleAutoFlush($options);
84 84
     }
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
      */
163 163
     public function flushTag(string $tag): void
164 164
     {
165
-        $this->tagIndex->flush($tag, function (string $cacheKey, string $namespace): void {
165
+        $this->tagIndex->flush($tag, function(string $cacheKey, string $namespace): void {
166 166
             $this->clearCache($cacheKey, $namespace);
167 167
         });
168 168
     }
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      * @return mixed
187 187
      * @throws CacheFileException
188 188
      */
189
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
189
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed
190 190
     {
191 191
         $ttlSeconds = CacheFileHelper::ttl($ttl, $this->defaultTTL);
192 192
         $cacheFile = $this->pathBuilder->build($cacheKey, $namespace);
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * @return array
247 247
      * @throws CacheFileException
248 248
      */
249
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
249
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array
250 250
     {
251 251
         $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL);
252 252
         $results = [];
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      * @return bool
287 287
      * @throws CacheFileException
288 288
      */
289
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool
289
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): bool
290 290
     {
291 291
         $cacheFile = $this->pathBuilder->build($cacheKey, $namespace);
292 292
         $data = $this->fileManager->serialize($cacheData);
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      * @return void
327 327
      * @throws CacheFileException
328 328
      */
329
-    public function renewCache(string $cacheKey, string|int $ttl, string $namespace = ''): void
329
+    public function renewCache(string $cacheKey, string | int $ttl, string $namespace = ''): void
330 330
     {
331 331
         $cacheData = $this->getCache($cacheKey, $namespace);
332 332
         if ($cacheData !== null) {
Please login to merge, or discard this patch.