Passed
Pull Request — main (#48)
by Sílvio
03:09
created
tests/Feature/FileCacheStoreFeatureTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
     public function test_remember_saves_and_recover_values()
93 93
     {
94 94
         $this->cache->flushCache();
95
-        $value = $this->cache->remember('remember_test_key', 60, function () {
95
+        $value = $this->cache->remember('remember_test_key', 60, function() {
96 96
             return 'valor_teste';
97 97
         });
98 98
         $this->assertEquals('valor_teste', $value);
99
-        $cachedValue = $this->cache->remember('remember_test_key', 60, function(){
99
+        $cachedValue = $this->cache->remember('remember_test_key', 60, function() {
100 100
             return 'novo_valor';
101 101
         });
102 102
         $this->assertEquals('valor_teste', $cachedValue);
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
     public function test_remember_forever_saves_value_indefinitely()
106 106
     {
107 107
         $this->cache->flushCache();
108
-        $value = $this->cache->rememberForever('remember_forever_key', function () {
108
+        $value = $this->cache->rememberForever('remember_forever_key', function() {
109 109
             return 'valor_eterno';
110 110
         });
111 111
         $this->assertEquals('valor_eterno', $value);
112
-        $cachedValue = $this->cache->rememberForever('remember_forever_key', function () {
112
+        $cachedValue = $this->cache->rememberForever('remember_forever_key', function() {
113 113
             return 'novo_valor';
114 114
         });
115 115
         $this->assertEquals('valor_eterno', $cachedValue);
Please login to merge, or discard this patch.
src/Service/CacheMutator.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
         $this->cacheer = $cacheer;
15 15
     }
16 16
 
17
-    public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
17
+    public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600)
18 18
     {
19 19
         if (!empty($this->cacheer->getCache($cacheKey, $namespace))) {
20 20
             return true;
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         return false;
69 69
     }
70 70
 
71
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): void
71
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600): void
72 72
     {
73 73
         $data = CacheerHelper::prepareForStorage($cacheData, $this->cacheer->isCompressionEnabled(), $this->cacheer->getEncryptionKey());
74 74
         $this->cacheer->cacheStore->putCache($cacheKey, $data, $namespace, $ttl);
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $this->cacheer->cacheStore->putMany($items, $namespace, $batchSize);
81 81
     }
82 82
 
83
-    public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
83
+    public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = ''): void
84 84
     {
85 85
         $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace);
86 86
         $this->cacheer->syncState();
Please login to merge, or discard this patch.
src/Service/CacheRetriever.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
         $this->cacheer = $cacheer;
17 17
     }
18 18
 
19
-    public function getCache(string $cacheKey, string $namespace = '', int|string $ttl = 3600)
19
+    public function getCache(string $cacheKey, string $namespace = '', int | string $ttl = 3600)
20 20
     {
21 21
         $cacheData = $this->cacheer->cacheStore->getCache($cacheKey, $namespace, $ttl);
22 22
         $this->cacheer->syncState();
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         return $this->cacheer->isFormatted() ? new CacheDataFormatter($cacheData) : $cacheData;
29 29
     }
30 30
 
31
-    public function getMany(array $cacheKeys, string $namespace = '', int|string $ttl = 3600)
31
+    public function getMany(array $cacheKeys, string $namespace = '', int | string $ttl = 3600)
32 32
     {
33 33
         $cachedData = $this->cacheer->cacheStore->getMany($cacheKeys, $namespace, $ttl);
34 34
         $this->cacheer->syncState();
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         return null;
70 70
     }
71 71
 
72
-    public function remember(string $cacheKey, int|string $ttl, Closure $callback)
72
+    public function remember(string $cacheKey, int | string $ttl, Closure $callback)
73 73
     {
74 74
         $cachedData = $this->getCache($cacheKey, ttl: $ttl);
75 75
 
Please login to merge, or discard this patch.
src/Cacheer.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -24,50 +24,50 @@  discard block
 block discarded – undo
24 24
 final class Cacheer implements CacheerInterface
25 25
 {
26 26
     /**
27
-    * @var string
28
-    */
27
+     * @var string
28
+     */
29 29
     private string $message;
30 30
 
31 31
     /**
32
-    * @var boolean
33
-    */
32
+     * @var boolean
33
+     */
34 34
     private bool $success;
35 35
 
36 36
     /**
37
-    * @var boolean
38
-    */
37
+     * @var boolean
38
+     */
39 39
     private bool $formatted = false;
40 40
 
41 41
     /**
42
-    * @var bool
43
-    */
42
+     * @var bool
43
+     */
44 44
     private bool $compression = false;
45 45
 
46 46
     /**
47
-    * @var string|null
48
-    */
47
+     * @var string|null
48
+     */
49 49
     private ?string $encryptionKey = null;
50 50
 
51 51
     /**
52
-    * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore
53
-    */
52
+     * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore
53
+     */
54 54
     public $cacheStore;
55 55
 
56 56
     /**
57
-    * @var array
58
-    */
57
+     * @var array
58
+     */
59 59
     public array $options = [];
60 60
 
61 61
     private CacheRetriever $retriever;
62 62
     private CacheMutator $mutator;
63 63
 
64 64
 /**
65
-    * Cacheer constructor.
66
-    *
67
-    * @param array $options
68
-    * @param bool  $formatted
69
-    * @throws RuntimeException
70
-    */
65
+ * Cacheer constructor.
66
+ *
67
+ * @param array $options
68
+ * @param bool  $formatted
69
+ * @throws RuntimeException
70
+ */
71 71
     public function __construct(array $options = [], $formatted = false)
72 72
     {
73 73
         $this->formatted = $formatted;
@@ -78,255 +78,255 @@  discard block
 block discarded – undo
78 78
     }
79 79
 
80 80
     /**
81
-    * Adds data to the cache if it does not already exist.
82
-    *
83
-    * @param string $cacheKey
84
-    * @param mixed  $cacheData
85
-    * @param string $namespace
86
-    * @param int|string $ttl
87
-    * @return bool
88
-    */
81
+     * Adds data to the cache if it does not already exist.
82
+     *
83
+     * @param string $cacheKey
84
+     * @param mixed  $cacheData
85
+     * @param string $namespace
86
+     * @param int|string $ttl
87
+     * @return bool
88
+     */
89 89
     public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
90 90
     {
91 91
         return $this->mutator->add($cacheKey, $cacheData, $namespace, $ttl);
92 92
     }
93 93
 
94 94
     /**
95
-    * Appends data to an existing cache item.
96
-    * 
97
-    * @param string $cacheKey
98
-    * @param mixed  $cacheData
99
-    * @param string $namespace
100
-    * @return void
101
-    */
95
+     * Appends data to an existing cache item.
96
+     * 
97
+     * @param string $cacheKey
98
+     * @param mixed  $cacheData
99
+     * @param string $namespace
100
+     * @return void
101
+     */
102 102
     public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): void
103 103
     {
104 104
         $this->mutator->appendCache($cacheKey, $cacheData, $namespace);
105 105
     }
106 106
 
107 107
     /**
108
-    * Clears a specific cache item.
109
-    * 
110
-    * @param string $cacheKey
111
-    * @param string $namespace
112
-    * @return void
113
-    */
108
+     * Clears a specific cache item.
109
+     * 
110
+     * @param string $cacheKey
111
+     * @param string $namespace
112
+     * @return void
113
+     */
114 114
     public function clearCache(string $cacheKey, string $namespace = ''): void
115 115
     {
116 116
         $this->mutator->clearCache($cacheKey, $namespace);
117 117
     }
118 118
 
119 119
     /**
120
-    * Decrements a cache item by a specified amount.
121
-    *  
122
-    * @param string $cacheKey
123
-    * @param int $amount
124
-    * @param string $namespace
125
-    * @return bool
126
-    */
120
+     * Decrements a cache item by a specified amount.
121
+     *  
122
+     * @param string $cacheKey
123
+     * @param int $amount
124
+     * @param string $namespace
125
+     * @return bool
126
+     */
127 127
     public function decrement(string $cacheKey, int $amount = 1, string $namespace = '')
128 128
     {
129 129
         return $this->mutator->decrement($cacheKey, $amount, $namespace);
130 130
     }
131 131
 
132 132
     /**
133
-    * Store data in the cache permanently.
134
-    *
135
-    * @param string $cacheKey
136
-    * @param mixed $cacheData
137
-    * @return void
138
-    */
133
+     * Store data in the cache permanently.
134
+     *
135
+     * @param string $cacheKey
136
+     * @param mixed $cacheData
137
+     * @return void
138
+     */
139 139
     public function forever(string $cacheKey, mixed $cacheData): void
140 140
     {
141 141
         $this->mutator->forever($cacheKey, $cacheData);
142 142
     }
143 143
 
144 144
     /**
145
-    * Flushes all cache items.
146
-    * 
147
-    * @return void
148
-    */
145
+     * Flushes all cache items.
146
+     * 
147
+     * @return void
148
+     */
149 149
     public function flushCache(): void
150 150
     {
151 151
         $this->mutator->flushCache();
152 152
     }
153 153
 
154 154
     /**
155
-    * Retrieves a cache item and deletes it from the cache.
156
-    * 
157
-    * @param string $cacheKey
158
-    * @param string $namespace
159
-    * @return mixed
160
-    */
155
+     * Retrieves a cache item and deletes it from the cache.
156
+     * 
157
+     * @param string $cacheKey
158
+     * @param string $namespace
159
+     * @return mixed
160
+     */
161 161
     public function getAndForget(string $cacheKey, string $namespace = '')
162 162
     {
163 163
         return $this->retriever->getAndForget($cacheKey, $namespace);
164 164
     }
165 165
 
166 166
     /**
167
-    * Gets all items in a specific namespace.
168
-    * 
169
-    * @param string $namespace
170
-    * @return CacheDataFormatter|mixed
171
-    */
167
+     * Gets all items in a specific namespace.
168
+     * 
169
+     * @param string $namespace
170
+     * @return CacheDataFormatter|mixed
171
+     */
172 172
     public function getAll(string $namespace = '')
173 173
     {
174 174
         return $this->retriever->getAll($namespace);
175 175
     }
176 176
 
177 177
     /**
178
-    * Retrieves a single cache item.
179
-    * 
180
-    * @param string $cacheKey
181
-    * @param string $namespace
182
-    * @param string|int $ttl
183
-    * @return CacheDataFormatter|mixed
184
-    */
178
+     * Retrieves a single cache item.
179
+     * 
180
+     * @param string $cacheKey
181
+     * @param string $namespace
182
+     * @param string|int $ttl
183
+     * @return CacheDataFormatter|mixed
184
+     */
185 185
     public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600)
186 186
     {
187 187
         return $this->retriever->getCache($cacheKey, $namespace, $ttl);
188 188
     }
189 189
 
190 190
     /**
191
-    * Retrieves multiple cache items by their keys.
192
-    * 
193
-    * @param array $cacheKeys
194
-    * @param string $namespace
195
-    * @param string|int $ttl
196
-    * @return CacheDataFormatter|mixed
197
-    */
191
+     * Retrieves multiple cache items by their keys.
192
+     * 
193
+     * @param array $cacheKeys
194
+     * @param string $namespace
195
+     * @param string|int $ttl
196
+     * @return CacheDataFormatter|mixed
197
+     */
198 198
     public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600)
199 199
     {
200 200
         return $this->retriever->getMany($cacheKeys, $namespace, $ttl);
201 201
     }
202 202
 
203 203
     /**
204
-    * Checks if a cache item exists.
205
-    * 
206
-    * @param string $cacheKey
207
-    * @param string $namespace
208
-    * @return void
209
-    */
204
+     * Checks if a cache item exists.
205
+     * 
206
+     * @param string $cacheKey
207
+     * @param string $namespace
208
+     * @return void
209
+     */
210 210
     public function has(string $cacheKey, string $namespace = ''): void
211 211
     {
212 212
         $this->retriever->has($cacheKey, $namespace);
213 213
     }
214 214
 
215 215
     /**
216
-    * Increments a cache item by a specified amount.
217
-    * 
218
-    * @param string $cacheKey
219
-    * @param int $amount
220
-    * @param string $namespace
221
-    * @return bool
222
-    */
216
+     * Increments a cache item by a specified amount.
217
+     * 
218
+     * @param string $cacheKey
219
+     * @param int $amount
220
+     * @param string $namespace
221
+     * @return bool
222
+     */
223 223
     public function increment(string $cacheKey, int $amount = 1, string $namespace = '')
224 224
     {
225 225
         return $this->mutator->increment($cacheKey, $amount, $namespace);
226 226
     }
227 227
 
228 228
     /**
229
-    * Checks if the last operation was successful.
230
-    * 
231
-    * @return boolean
232
-    */
229
+     * Checks if the last operation was successful.
230
+     * 
231
+     * @return boolean
232
+     */
233 233
     public function isSuccess()
234 234
     {
235 235
         return $this->success;
236 236
     }
237 237
 
238 238
     /**
239
-    * Stores an item in the cache with a specific TTL.
240
-    * 
241
-    * @param string $cacheKey
242
-    * @param mixed  $cacheData
243
-    * @param string $namespace
244
-    * @param string|int $ttl
245
-    * @return void
246
-    */
239
+     * Stores an item in the cache with a specific TTL.
240
+     * 
241
+     * @param string $cacheKey
242
+     * @param mixed  $cacheData
243
+     * @param string $namespace
244
+     * @param string|int $ttl
245
+     * @return void
246
+     */
247 247
     public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): void
248 248
     {
249 249
         $this->mutator->putCache($cacheKey, $cacheData, $namespace, $ttl);
250 250
     }
251 251
 
252 252
     /**
253
-    * Stores multiple items in the cache.
254
-    *  
255
-    * @param array   $items
256
-    * @param string  $namespace
257
-    * @param integer $batchSize
258
-    * @return void
259
-    */
253
+     * Stores multiple items in the cache.
254
+     *  
255
+     * @param array   $items
256
+     * @param string  $namespace
257
+     * @param integer $batchSize
258
+     * @return void
259
+     */
260 260
     public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
261 261
     {
262 262
         $this->mutator->putMany($items, $namespace, $batchSize);
263 263
     }
264 264
 
265 265
     /**
266
-    * Renews the cache for a specific key with a new TTL.
267
-    * 
268
-    * @param string $cacheKey
269
-    * @param string|int $ttl
270
-    * @param string $namespace
271
-    * @return void
272
-    */
266
+     * Renews the cache for a specific key with a new TTL.
267
+     * 
268
+     * @param string $cacheKey
269
+     * @param string|int $ttl
270
+     * @param string $namespace
271
+     * @return void
272
+     */
273 273
     public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): void
274 274
     {
275 275
         $this->mutator->renewCache($cacheKey, $ttl, $namespace);
276 276
     }
277 277
 
278 278
     /**
279
-    * Retrieves a cache item or executes a callback to store it if not found.
280
-    * 
281
-    * @param string $cacheKey
282
-    * @param int|string $ttl
283
-    * @param Closure $callback
284
-    * @return mixed
285
-    */
279
+     * Retrieves a cache item or executes a callback to store it if not found.
280
+     * 
281
+     * @param string $cacheKey
282
+     * @param int|string $ttl
283
+     * @param Closure $callback
284
+     * @return mixed
285
+     */
286 286
     public function remember(string $cacheKey, int|string $ttl, Closure $callback)
287 287
     {
288 288
         return $this->retriever->remember($cacheKey, $ttl, $callback);
289 289
     }
290 290
 
291 291
     /**
292
-    * Retrieves a cache item or executes a callback to store it permanently if not found.
293
-    * 
294
-    * @param string $cacheKey
295
-    * @param Closure $callback
296
-    * @return mixed
297
-    */
292
+     * Retrieves a cache item or executes a callback to store it permanently if not found.
293
+     * 
294
+     * @param string $cacheKey
295
+     * @param Closure $callback
296
+     * @return mixed
297
+     */
298 298
     public function rememberForever(string $cacheKey, Closure $callback)
299 299
     {
300 300
         return $this->retriever->rememberForever($cacheKey, $callback);
301 301
     }
302 302
 
303 303
     /**
304
-    * Returns a CacheConfig instance for configuration management.
305
-    * 
306
-    * @return CacheConfig
307
-    */
304
+     * Returns a CacheConfig instance for configuration management.
305
+     * 
306
+     * @return CacheConfig
307
+     */
308 308
     public function setConfig()
309 309
     {
310 310
         return new CacheConfig($this);
311 311
     }
312 312
 
313 313
     /**
314
-    * Sets the cache driver based on the configuration.
315
-    * 
316
-    * @return CacheDriver
317
-    */
314
+     * Sets the cache driver based on the configuration.
315
+     * 
316
+     * @return CacheDriver
317
+     */
318 318
     public function setDriver()
319 319
     {
320 320
         return new CacheDriver($this);
321 321
     }
322 322
 
323 323
     /**
324
-    * Sets a message for the cache operation.
325
-    *
326
-    * @param string  $message
327
-    * @param boolean $success
328
-    * @return void
329
-    */
324
+     * Sets a message for the cache operation.
325
+     *
326
+     * @param string  $message
327
+     * @param boolean $success
328
+     * @return void
329
+     */
330 330
     private function setMessage(string $message, bool $success)
331 331
     {
332 332
         $this->message = $message;
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
     }
335 335
 
336 336
     /**
337
-    * Retrieves the message from the last operation.
338
-    * 
339
-    * @return string
340
-    */
337
+     * Retrieves the message from the last operation.
338
+     * 
339
+     * @return string
340
+     */
341 341
     public function getMessage()
342 342
     {
343 343
         return $this->message;
@@ -369,32 +369,32 @@  discard block
 block discarded – undo
369 369
     }
370 370
 
371 371
     /**
372
-    * Enables or disables the formatter for cache data.
373
-    * 
374
-    * @return void
375
-    */
372
+     * Enables or disables the formatter for cache data.
373
+     * 
374
+     * @return void
375
+     */
376 376
     public function useFormatter()
377 377
     {
378 378
         $this->formatted = !$this->formatted;
379 379
     }
380 380
 
381 381
     /**
382
-    * Validates the options provided for the Cacheer instance.
383
-    * 
384
-    * @param array $options
385
-    * @return void
386
-    */
382
+     * Validates the options provided for the Cacheer instance.
383
+     * 
384
+     * @param array $options
385
+     * @return void
386
+     */
387 387
     private function validateOptions(array $options)
388 388
     {
389 389
         $this->options = $options;
390 390
     }
391 391
 
392 392
     /**
393
-    * Enable or disable data compression
394
-    *
395
-    * @param bool $status
396
-    * @return $this
397
-    */
393
+     * Enable or disable data compression
394
+     *
395
+     * @param bool $status
396
+     * @return $this
397
+     */
398 398
     public function useCompression(bool $status = true)
399 399
     {
400 400
         $this->compression = $status;
@@ -402,11 +402,11 @@  discard block
 block discarded – undo
402 402
     }
403 403
 
404 404
     /**
405
-    * Enable encryption for cached data
406
-    *
407
-    * @param string $key
408
-    * @return $this
409
-    */
405
+     * Enable encryption for cached data
406
+     *
407
+     * @param string $key
408
+     * @return $this
409
+     */
410 410
     public function useEncryption(string $key)
411 411
     {
412 412
         $this->encryptionKey = $key;
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     * @param int|string $ttl
87 87
     * @return bool
88 88
     */
89
-    public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
89
+    public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600)
90 90
     {
91 91
         return $this->mutator->add($cacheKey, $cacheData, $namespace, $ttl);
92 92
     }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     * @param string|int $ttl
183 183
     * @return CacheDataFormatter|mixed
184 184
     */
185
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600)
185
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600)
186 186
     {
187 187
         return $this->retriever->getCache($cacheKey, $namespace, $ttl);
188 188
     }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     * @param string|int $ttl
196 196
     * @return CacheDataFormatter|mixed
197 197
     */
198
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600)
198
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600)
199 199
     {
200 200
         return $this->retriever->getMany($cacheKeys, $namespace, $ttl);
201 201
     }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
     * @param string|int $ttl
245 245
     * @return void
246 246
     */
247
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): void
247
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): void
248 248
     {
249 249
         $this->mutator->putCache($cacheKey, $cacheData, $namespace, $ttl);
250 250
     }
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     * @param string $namespace
271 271
     * @return void
272 272
     */
273
-    public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): void
273
+    public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = ''): void
274 274
     {
275 275
         $this->mutator->renewCache($cacheKey, $ttl, $namespace);
276 276
     }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
     * @param Closure $callback
284 284
     * @return mixed
285 285
     */
286
-    public function remember(string $cacheKey, int|string $ttl, Closure $callback)
286
+    public function remember(string $cacheKey, int | string $ttl, Closure $callback)
287 287
     {
288 288
         return $this->retriever->remember($cacheKey, $ttl, $callback);
289 289
     }
Please login to merge, or discard this patch.