Passed
Pull Request — main (#61)
by Sílvio
02:56
created
src/Exceptions/ConnectionException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -53,23 +53,23 @@
 block discarded – undo
53 53
     }
54 54
     
55 55
     /**
56
-    * Converts the exception to a JSON serializable format.
57
-    * 
58
-    * @return string
59
-    */
56
+     * Converts the exception to a JSON serializable format.
57
+     * 
58
+     * @return string
59
+     */
60 60
     public function jsonSerialize(): array
61 61
     {
62 62
         return parent::jsonSerialize();
63 63
     }
64 64
 
65 65
     /**
66
-    * Converts the exception to a JSON string.
67
-    *
68
-    * @param int $options
69
-    * @return string
70
-    */
66
+     * Converts the exception to a JSON string.
67
+     *
68
+     * @param int $options
69
+     * @return string
70
+     */
71 71
     public function toJson(int $options = 0)
72 72
     {
73
-      return parent::toJson($options);
73
+        return parent::toJson($options);
74 74
     }
75 75
 }
Please login to merge, or discard this patch.
src/CacheStore/FileCacheStore.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -43,18 +43,18 @@
 block discarded – undo
43 43
 
44 44
 
45 45
     /**
46
-    * @var CacheLogger
47
-    */
46
+     * @var CacheLogger
47
+     */
48 48
     private $logger = null;
49 49
 
50 50
     /**
51
-    * @var FileCacheManager
52
-    */
51
+     * @var FileCacheManager
52
+     */
53 53
     private FileCacheManager $fileManager;
54 54
 
55 55
     /**
56
-    * @var FileCacheFlusher
57
-    */
56
+     * @var FileCacheFlusher
57
+     */
58 58
     private FileCacheFlusher $flusher;
59 59
 
60 60
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @return mixed
190 190
      * @throws CacheFileException return string|void
191 191
      */
192
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
192
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed
193 193
     {
194 194
        
195 195
         $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL);
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
      * @return array
278 278
      * @throws CacheFileException
279 279
      */
280
-    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
280
+    public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array
281 281
     {
282 282
         $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL);
283 283
         $results = [];
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
      * @return void
325 325
      * @throws CacheFileException
326 326
      */
327
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): void
327
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): void
328 328
     {
329 329
         $cacheFile = $this->buildCacheFilePath($cacheKey, $namespace);
330 330
         $data = $this->fileManager->serialize($cacheData);
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @return void
364 364
      * @throws CacheFileException
365 365
      */
366
-    public function renewCache(string $cacheKey, string|int $ttl, string $namespace = ''): void
366
+    public function renewCache(string $cacheKey, string | int $ttl, string $namespace = ''): void
367 367
     {
368 368
         $cacheData = $this->getCache($cacheKey, $namespace);
369 369
         if ($cacheData) {
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/FileCacheFlusher.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
             return;
53 53
         }
54 54
 
55
-        $lastFlushTime = (int) $this->fileManager->readFile($this->lastFlushTimeFile);
55
+        $lastFlushTime = (int)$this->fileManager->readFile($this->lastFlushTimeFile);
56 56
 
57 57
         if ((time() - $lastFlushTime) >= $flushAfterSeconds) {
58 58
             $this->flushCache();
Please login to merge, or discard this 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/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.
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/CacheStore/ArrayCacheStore.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
    * @param int|string $ttl
141 141
    * @return mixed
142 142
    */
143
-  public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed
143
+  public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed
144 144
   {
145 145
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
146 146
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
    * @param string|int $ttl
230 230
    * @return array
231 231
    */
232
-  public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array
232
+  public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array
233 233
   {
234 234
     $results = [];
235 235
     foreach ($cacheKeys as $cacheKey) {
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
   {
264 264
     $cacheData = $this->getCache($cacheKey, $namespace);
265 265
 
266
-    if(!empty($cacheData) && is_numeric($cacheData)) {
266
+    if (!empty($cacheData) && is_numeric($cacheData)) {
267 267
       $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
268 268
       $this->setMessage($this->getMessage(), $this->isSuccess());
269 269
       return true;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
    * @param int|string $ttl
302 302
    * @return bool
303 303
    */
304
-  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
304
+  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600): bool
305 305
   {
306 306
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
307 307
 
@@ -344,12 +344,12 @@  discard block
 block discarded – undo
344 344
    * @param string $namespace
345 345
    * @return void
346 346
    */
347
-  public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
347
+  public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = ''): void
348 348
   {
349 349
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
350 350
 
351 351
     if (isset($this->arrayStore[$arrayStoreKey])) {
352
-        $ttlSeconds = is_numeric($ttl) ? (int) $ttl : strtotime($ttl) - time();
352
+        $ttlSeconds = is_numeric($ttl) ? (int)$ttl : strtotime($ttl) - time();
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.");
Please login to merge, or discard this patch.
Indentation   +281 added lines, -281 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,234 +126,234 @@  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
     $exists = isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime'];
252 252
 
253 253
     $this->setMessage(
254
-      $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!",
255
-      $exists
254
+        $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!",
255
+        $exists
256 256
     );
257 257
     $this->logger->debug("{$this->getMessage()} from array driver.");
258 258
 
259 259
     return $exists;
260
-  }
261
-
262
-  /**
263
-   * Increments a cache item by a specified amount.
264
-   * 
265
-   * @param string $cacheKey
266
-   * @param int $amount
267
-   * @param string $namespace
268
-   * @return bool
269
-   */
270
-  public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool
271
-  {
260
+    }
261
+
262
+    /**
263
+     * Increments a cache item by a specified amount.
264
+     * 
265
+     * @param string $cacheKey
266
+     * @param int $amount
267
+     * @param string $namespace
268
+     * @return bool
269
+     */
270
+    public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool
271
+    {
272 272
     $cacheData = $this->getCache($cacheKey, $namespace);
273 273
 
274 274
     if(!empty($cacheData) && is_numeric($cacheData)) {
275
-      $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
276
-      $this->setMessage($this->getMessage(), $this->isSuccess());
277
-      return true;
275
+        $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
276
+        $this->setMessage($this->getMessage(), $this->isSuccess());
277
+        return true;
278 278
     }
279 279
 
280 280
     return false;
281
-  }
282
-
283
-  /**
284
-   * Checks if the operation was successful.
285
-   * 
286
-   * @return boolean
287
-   */
288
-  public function isSuccess(): bool
289
-  {
281
+    }
282
+
283
+    /**
284
+     * Checks if the operation was successful.
285
+     * 
286
+     * @return boolean
287
+     */
288
+    public function isSuccess(): bool
289
+    {
290 290
     return $this->success;
291
-  }
292
-
293
-  /**
294
-   * Gets the last message.
295
-   * 
296
-   * @return string
297
-   */
298
-  public function getMessage(): string
299
-  {
291
+    }
292
+
293
+    /**
294
+     * Gets the last message.
295
+     * 
296
+     * @return string
297
+     */
298
+    public function getMessage(): string
299
+    {
300 300
     return $this->message;
301
-  }
302
-
303
-  /**
304
-   * Stores an item in the cache with a specific TTL.
305
-   * 
306
-   * @param string $cacheKey
307
-   * @param mixed $cacheData
308
-   * @param string $namespace
309
-   * @param int|string $ttl
310
-   * @return bool
311
-   */
312
-  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
313
-  {
301
+    }
302
+
303
+    /**
304
+     * Stores an item in the cache with a specific TTL.
305
+     * 
306
+     * @param string $cacheKey
307
+     * @param mixed $cacheData
308
+     * @param string $namespace
309
+     * @param int|string $ttl
310
+     * @return bool
311
+     */
312
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
313
+    {
314 314
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
315 315
 
316 316
     $this->arrayStore[$arrayStoreKey] = [
317
-      'cacheData' => serialize($cacheData),
318
-      'expirationTime' => time() + $ttl
317
+        'cacheData' => serialize($cacheData),
318
+        'expirationTime' => time() + $ttl
319 319
     ];
320 320
 
321 321
     $this->setMessage("Cache stored successfully", true);
322 322
     $this->logger->debug("{$this->getMessage()} from Array driver.");
323 323
     return true;
324
-  }
325
-
326
-  /**
327
-   * Stores multiple items in the cache in batches.
328
-   * 
329
-   * @param array $items
330
-   * @param string $namespace
331
-   * @param int $batchSize
332
-   * @return void
333
-   */
334
-  public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
335
-  {
324
+    }
325
+
326
+    /**
327
+     * Stores multiple items in the cache in batches.
328
+     * 
329
+     * @param array $items
330
+     * @param string $namespace
331
+     * @param int $batchSize
332
+     * @return void
333
+     */
334
+    public function putMany(array $items, string $namespace = '', int $batchSize = 100): void
335
+    {
336 336
     $chunks = array_chunk($items, $batchSize, true);
337 337
 
338 338
     foreach ($chunks as $chunk) {
339
-      foreach ($chunk as $key => $data) {
340
-          $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
339
+        foreach ($chunk as $key => $data) {
340
+            $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
341
+        }
341 342
         }
342
-      }
343 343
     $this->setMessage("{$this->getMessage()}", $this->isSuccess());
344 344
     $this->logger->debug("{$this->getMessage()} from Array driver.");
345
-  }
346
-
347
-  /**
348
-   * Renews the expiration time of a cache item.
349
-   * 
350
-   * @param string $cacheKey
351
-   * @param string|int $ttl
352
-   * @param string $namespace
353
-   * @return void
354
-   */
355
-  public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
356
-  {
345
+    }
346
+
347
+    /**
348
+     * Renews the expiration time of a cache item.
349
+     * 
350
+     * @param string $cacheKey
351
+     * @param string|int $ttl
352
+     * @param string $namespace
353
+     * @return void
354
+     */
355
+    public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void
356
+    {
357 357
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
358 358
 
359 359
     if (isset($this->arrayStore[$arrayStoreKey])) {
@@ -361,31 +361,31 @@  discard block
 block discarded – undo
361 361
         $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds;
362 362
         $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true);
363 363
         $this->logger->debug("{$this->getMessage()} from array driver.");
364
-      }
365
-  }
366
-
367
-  /**
368
-   * Sets a message and its success status.
369
-   * 
370
-   * @param string  $message
371
-   * @param boolean $success
372
-   * @return void
373
-   */
374
-  private function setMessage(string $message, bool $success): void
375
-  {
364
+        }
365
+    }
366
+
367
+    /**
368
+     * Sets a message and its success status.
369
+     * 
370
+     * @param string  $message
371
+     * @param boolean $success
372
+     * @return void
373
+     */
374
+    private function setMessage(string $message, bool $success): void
375
+    {
376 376
     $this->message = $message;
377 377
     $this->success = $success;
378
-  }
379
-
380
-  /**
381
-   * Serializes or unserializes data based on the flag.
382
-   * 
383
-   * @param mixed $data
384
-   * @param bool $serialize
385
-   * @return mixed
386
-   */
387
-  private function serialize(mixed $data, bool $serialize = true): mixed
388
-  {
378
+    }
379
+
380
+    /**
381
+     * Serializes or unserializes data based on the flag.
382
+     * 
383
+     * @param mixed $data
384
+     * @param bool $serialize
385
+     * @return mixed
386
+     */
387
+    private function serialize(mixed $data, bool $serialize = true): mixed
388
+    {
389 389
     return $serialize ? serialize($data) : unserialize($data);
390
-  }
390
+    }
391 391
 }
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/FileCacheManager.php 2 patches
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.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @return string|bool
45 45
      * @throws CacheFileException
46 46
      */
47
-    public function readFile(string $filename): string|bool
47
+    public function readFile(string $filename): string | bool
48 48
     {
49 49
         if (!$this->fileExists($filename)) {
50 50
             throw CacheFileException::create("File not found: {$filename}");
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     public function serialize(mixed $data, bool $serialize = true): mixed
97 97
     {
98
-        if($serialize) {
98
+        if ($serialize) {
99 99
             return serialize($data);
100 100
         }
101 101
         return unserialize($data);
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/RedisCacheManager.php 2 patches
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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
   */
48 48
   private static function auth(): void
49 49
   {
50
-    if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
50
+    if (is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
51 51
       self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
52 52
     }
53 53
   }
Please login to merge, or discard this patch.
src/Repositories/CacheDatabaseRepository.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      * @param string|int $ttl
38 38
      * @return bool
39 39
      */
40
-    public function store(string $cacheKey, mixed $cacheData, string $namespace, string|int $ttl = 3600): bool
40
+    public function store(string $cacheKey, mixed $cacheData, string $namespace, string | int $ttl = 3600): bool
41 41
     {
42 42
         if (!empty($this->retrieve($cacheKey, $namespace))) {
43 43
             return $this->update($cacheKey, $cacheData, $namespace);
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
     * @param string $namespace
223 223
     * @return bool
224 224
     */
225
-    public function renew(string $cacheKey, string|int $ttl, string $namespace = ''): bool
225
+    public function renew(string $cacheKey, string | int $ttl, string $namespace = ''): bool
226 226
     {
227 227
         $currentTime = date('Y-m-d H:i:s');
228 228
         if (!$this->hasValidCache($cacheKey, $namespace, $currentTime)) {
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
         $query = $this->getRenewExpirationQueryWithDriver();
233 233
         $stmt = $this->connection->prepare($query);
234
-        $stmt->bindValue(':ttl', (int) $ttl, PDO::PARAM_INT);
234
+        $stmt->bindValue(':ttl', (int)$ttl, PDO::PARAM_INT);
235 235
         $stmt->bindValue(':cacheKey', $cacheKey);
236 236
         $stmt->bindValue(':namespace', $namespace);
237 237
         $stmt->bindValue(':currentTime', $currentTime);
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
     }
65 65
 
66 66
     /**
67
-    * Retrieves cache data from the database.
68
-    * 
69
-    * @param string $cacheKey
70
-    * @param string $namespace
71
-    * @return mixed
67
+     * Retrieves cache data from the database.
68
+     * 
69
+     * @param string $cacheKey
70
+     * @param string $namespace
71
+     * @return mixed
72 72
      */
73 73
     public function retrieve(string $cacheKey, string $namespace = ''): mixed
74 74
     {
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
     }
114 114
 
115 115
     /**
116
-    * Get Update query based on the database driver.
117
-    *
118
-    * @return string
119
-    */
116
+     * Get Update query based on the database driver.
117
+     *
118
+     * @return string
119
+     */
120 120
     private function getUpdateQueryWithDriver(): string
121 121
     {
122 122
         $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
     }
128 128
 
129 129
     /**
130
-    * Get Delete query based on the database driver.
131
-    * 
132
-    * @return string
133
-    */
130
+     * Get Delete query based on the database driver.
131
+     * 
132
+     * @return string
133
+     */
134 134
     private function getDeleteQueryWithDriver(): string
135 135
     {
136 136
         $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
     }
142 142
 
143 143
     /**
144
-    * Updates an existing cache item in the database.
145
-    * 
146
-    * @param string $cacheKey
147
-    * @param mixed  $cacheData
148
-    * @param string $namespace
149
-    * @return bool
150
-    */
144
+     * Updates an existing cache item in the database.
145
+     * 
146
+     * @param string $cacheKey
147
+     * @param mixed  $cacheData
148
+     * @param string $namespace
149
+     * @return bool
150
+     */
151 151
     public function update(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
152 152
     {
153 153
         $query = $this->getUpdateQueryWithDriver();
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
     }
162 162
 
163 163
     /**
164
-    * Clears a specific cache item from the database.
165
-    * 
166
-    * @param string $cacheKey
167
-    * @param string $namespace
168
-    * @return bool
169
-    */
164
+     * Clears a specific cache item from the database.
165
+     * 
166
+     * @param string $cacheKey
167
+     * @param string $namespace
168
+     * @return bool
169
+     */
170 170
     public function clear(string $cacheKey, string $namespace = ''): bool
171 171
     {
172 172
         $query = $this->getDeleteQueryWithDriver();
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
     }
180 180
 
181 181
     /**
182
-    * Gets the query to renew the expiration time of a cache item based on the database driver.
183
-    *  
184
-    * @return string
185
-    */
182
+     * Gets the query to renew the expiration time of a cache item based on the database driver.
183
+     *  
184
+     * @return string
185
+     */
186 186
     private function getRenewExpirationQueryWithDriver(): string
187 187
     {
188 188
         $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
     }
198 198
 
199 199
     /**
200
-    * Checks if a cache item is valid based on its key, namespace, and current time.
201
-    * 
202
-    * @param string $cacheKey
203
-    * @param string $namespace
204
-    * @param string $currentTime
205
-    * @return bool
206
-    */
200
+     * Checks if a cache item is valid based on its key, namespace, and current time.
201
+     * 
202
+     * @param string $cacheKey
203
+     * @param string $namespace
204
+     * @param string $currentTime
205
+     * @return bool
206
+     */
207 207
     private function hasValidCache(string $cacheKey, string $namespace, string $currentTime): bool
208 208
     {
209 209
         $stmt = $this->connection->prepare(
@@ -219,13 +219,13 @@  discard block
 block discarded – undo
219 219
     }
220 220
 
221 221
     /**
222
-    * Renews the expiration time of a cache item.
223
-    * 
224
-    * @param string $cacheKey
225
-    * @param string|int $ttl
226
-    * @param string $namespace
227
-    * @return bool
228
-    */
222
+     * Renews the expiration time of a cache item.
223
+     * 
224
+     * @param string $cacheKey
225
+     * @param string|int $ttl
226
+     * @param string $namespace
227
+     * @return bool
228
+     */
229 229
     public function renew(string $cacheKey, string|int $ttl, string $namespace = ''): bool
230 230
     {
231 231
         $currentTime = date('Y-m-d H:i:s');
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
     }
246 246
 
247 247
     /**
248
-    * Flushes all cache items from the database.
249
-    * 
250
-    * @return bool
251
-    */
248
+     * Flushes all cache items from the database.
249
+     * 
250
+     * @return bool
251
+     */
252 252
     public function flush(): bool
253 253
     {
254 254
         return $this->connection->exec("DELETE FROM {$this->table}") !== false;
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
     }
268 268
 
269 269
     /**
270
-    * Gets the current date and time based on the database driver.
271
-    * 
272
-    * @param string $driver
273
-    * @return string
274
-    */
270
+     * Gets the current date and time based on the database driver.
271
+     * 
272
+     * @param string $driver
273
+     * @return string
274
+     */
275 275
     private function getCurrentDateTime(string $driver): string
276 276
     {
277 277
         return ($driver === 'sqlite') ? "DATETIME('now', 'localtime')" : "NOW()";
Please login to merge, or discard this patch.