@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | { |
259 | 259 | $this->cache->flushCache(); |
260 | 260 | |
261 | - $value = $this->cache->remember('remember_test_key', 60, function () { |
|
261 | + $value = $this->cache->remember('remember_test_key', 60, function() { |
|
262 | 262 | return 'valor_teste'; |
263 | 263 | }); |
264 | 264 | |
265 | 265 | $this->assertEquals('valor_teste', $value); |
266 | 266 | |
267 | - $cachedValue = $this->cache->remember('remember_test_key', 60, function (){ |
|
267 | + $cachedValue = $this->cache->remember('remember_test_key', 60, function() { |
|
268 | 268 | return 'novo_valor'; |
269 | 269 | }); |
270 | 270 | |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | { |
277 | 277 | $this->cache->flushCache(); |
278 | 278 | |
279 | - $value = $this->cache->rememberForever('remember_forever_key', function () { |
|
279 | + $value = $this->cache->rememberForever('remember_forever_key', function() { |
|
280 | 280 | return 'valor_eterno'; |
281 | 281 | }); |
282 | 282 | $this->assertEquals('valor_eterno', $value); |
283 | 283 | |
284 | - $cachedValue = $this->cache->rememberForever('remember_forever_key', function () { |
|
284 | + $cachedValue = $this->cache->rememberForever('remember_forever_key', function() { |
|
285 | 285 | return 'novo_valor'; |
286 | 286 | }); |
287 | 287 |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
21 | 21 | { |
22 | - return new self(self::getBefore() . ": " .$message, $code, $previous, $details); |
|
22 | + return new self(self::getBefore() . ": " . $message, $code, $previous, $details); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string|int $ttl |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public function store(string $cacheKey, mixed $cacheData, string $namespace, string|int $ttl = 3600) |
|
32 | + public function store(string $cacheKey, mixed $cacheData, string $namespace, string | int $ttl = 3600) |
|
33 | 33 | { |
34 | 34 | if (!empty($this->retrieve($cacheKey, $namespace))) { |
35 | 35 | return $this->update($cacheKey, $cacheData, $namespace); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param string $namespace |
175 | 175 | * @return bool |
176 | 176 | */ |
177 | - public function renew(string $cacheKey, string|int $ttl, string $namespace = '') |
|
177 | + public function renew(string $cacheKey, string | int $ttl, string $namespace = '') |
|
178 | 178 | { |
179 | 179 | $currentTime = date('Y-m-d H:i:s'); |
180 | 180 | if (!$this->hasValidCache($cacheKey, $namespace, $currentTime)) { |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | |
184 | 184 | $query = $this->getRenewExpirationQueryWithDriver(); |
185 | 185 | $stmt = $this->connection->prepare($query); |
186 | - $stmt->bindValue(':ttl', (int) $ttl, PDO::PARAM_INT); |
|
186 | + $stmt->bindValue(':ttl', (int)$ttl, PDO::PARAM_INT); |
|
187 | 187 | $stmt->bindValue(':cacheKey', $cacheKey); |
188 | 188 | $stmt->bindValue(':namespace', $namespace); |
189 | 189 | $stmt->bindValue(':currentTime', $currentTime); |
@@ -91,7 +91,7 @@ |
||
91 | 91 | */ |
92 | 92 | public function serialize(mixed $data, bool $serialize = true) |
93 | 93 | { |
94 | - if($serialize) { |
|
94 | + if ($serialize) { |
|
95 | 95 | return serialize($data); |
96 | 96 | } |
97 | 97 | return unserialize($data); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string|int $ttl |
119 | 119 | * @return mixed |
120 | 120 | */ |
121 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
121 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
122 | 122 | { |
123 | 123 | $fullCacheKey = $this->buildKey($cacheKey, $namespace); |
124 | 124 | $cacheData = $this->redis->get($fullCacheKey); |
@@ -201,12 +201,12 @@ discard block |
||
201 | 201 | * @param string|int|null $ttl |
202 | 202 | * @return mixed |
203 | 203 | */ |
204 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null) |
|
204 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int | null $ttl = null) |
|
205 | 205 | { |
206 | 206 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
207 | 207 | $serializedData = CacheRedisHelper::serialize($cacheData); |
208 | 208 | |
209 | - $result = $ttl ? $this->redis->setex($cacheFullKey, (int) $ttl, $serializedData) |
|
209 | + $result = $ttl ? $this->redis->setex($cacheFullKey, (int)$ttl, $serializedData) |
|
210 | 210 | : $this->redis->set($cacheFullKey, $serializedData); |
211 | 211 | |
212 | 212 | if ($result) { |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @param string $namespace |
244 | 244 | * @return void |
245 | 245 | */ |
246 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
246 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
247 | 247 | { |
248 | 248 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
249 | 249 | $dump = $this->getDump($cacheFullKey); |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @param mixed $dump |
272 | 272 | * @return bool |
273 | 273 | */ |
274 | - private function restoreKey(string $fullKey, string|int $ttl, mixed $dump) |
|
274 | + private function restoreKey(string $fullKey, string | int $ttl, mixed $dump) |
|
275 | 275 | { |
276 | 276 | try { |
277 | 277 | $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param int|string $ttl |
124 | 124 | * @return mixed |
125 | 125 | */ |
126 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
126 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
127 | 127 | { |
128 | 128 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
129 | 129 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $expirationTime = $cacheData['expirationTime'] ?? 0; |
138 | 138 | $now = time(); |
139 | 139 | |
140 | - if($expirationTime !== 0 && $now >= $expirationTime) { |
|
140 | + if ($expirationTime !== 0 && $now >= $expirationTime) { |
|
141 | 141 | list($np, $key) = explode(':', $arrayStoreKey); |
142 | 142 | $this->clearCache($key, $np); |
143 | 143 | $this->setMessage("cacheKey: {$key} has expired.", false); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | { |
172 | 172 | $cacheData = $this->getCache($cacheKey, $namespace); |
173 | 173 | |
174 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
174 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
175 | 175 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
176 | 176 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
177 | 177 | return true; |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param int|string $ttl |
204 | 204 | * @return bool |
205 | 205 | */ |
206 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
206 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
207 | 207 | { |
208 | 208 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
209 | 209 | |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | * @param string $namespace |
243 | 243 | * @return void |
244 | 244 | */ |
245 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
|
245 | + public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = '') |
|
246 | 246 | { |
247 | 247 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
248 | 248 | |
249 | 249 | if (isset($this->arrayStore[$arrayStoreKey])) { |
250 | - $ttlSeconds = is_numeric($ttl) ? (int) $ttl : strtotime($ttl) - time(); |
|
250 | + $ttlSeconds = is_numeric($ttl) ? (int)$ttl : strtotime($ttl) - time(); |
|
251 | 251 | $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds; |
252 | 252 | $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true); |
253 | 253 | $this->logger->debug("{$this->getMessage()} from array driver."); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function clearCache(string $cacheKey, string $namespace = '') |
69 | 69 | { |
70 | 70 | $data = $this->cacheRepository->clear($cacheKey, $namespace); |
71 | - if($data) { |
|
71 | + if ($data) { |
|
72 | 72 | $this->setMessage("Cache deleted successfully!", true); |
73 | 73 | } else { |
74 | 74 | $this->setMessage("Cache does not exists!", false); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function flushCache() |
84 | 84 | { |
85 | - if($this->cacheRepository->flush()){ |
|
85 | + if ($this->cacheRepository->flush()) { |
|
86 | 86 | $this->setMessage("Flush finished successfully", true); |
87 | 87 | } else { |
88 | 88 | $this->setMessage("Something went wrong. Please, try again.", false); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param string|int $ttl |
99 | 99 | * @return mixed |
100 | 100 | */ |
101 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
101 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
102 | 102 | { |
103 | 103 | $cacheData = $this->retrieveCache($cacheKey, $namespace); |
104 | 104 | if ($cacheData) { |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | * @param string|int $ttl |
166 | 166 | * @return bool |
167 | 167 | */ |
168 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
168 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
169 | 169 | { |
170 | - if($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)){ |
|
170 | + if ($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)) { |
|
171 | 171 | $this->logger->debug("{$this->getMessage()} from database driver."); |
172 | 172 | return true; |
173 | 173 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | private function processBatchItems(array $batchItems, string $namespace) |
200 | 200 | { |
201 | - foreach($batchItems as $item) { |
|
201 | + foreach ($batchItems as $item) { |
|
202 | 202 | CacheDatabaseHelper::validateCacheItem($item); |
203 | 203 | $cacheKey = $item['cacheKey']; |
204 | 204 | $cacheData = $item['cacheData']; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param string $namespace |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | - private function renew(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
216 | + private function renew(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
217 | 217 | { |
218 | 218 | $cacheData = $this->getCache($cacheKey, $namespace); |
219 | 219 | if ($cacheData) { |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | * @param integer $ttl |
257 | 257 | * @return bool |
258 | 258 | */ |
259 | - private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
259 | + private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
260 | 260 | { |
261 | 261 | $data = $this->cacheRepository->store($cacheKey, $cacheData, $namespace, $ttl); |
262 | - if($data) { |
|
262 | + if ($data) { |
|
263 | 263 | $this->setMessage("Cache Stored Successfully", true); |
264 | 264 | return true; |
265 | 265 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | private function updateCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
277 | 277 | { |
278 | 278 | $data = $this->cacheRepository->update($cacheKey, $cacheData, $namespace); |
279 | - if($data) { |
|
279 | + if ($data) { |
|
280 | 280 | $this->setMessage("Cache updated successfully.", true); |
281 | 281 | return true; |
282 | 282 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param int|string $ttl |
59 | 59 | * @return bool |
60 | 60 | */ |
61 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
61 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
62 | 62 | { |
63 | 63 | if (!empty($this->getCache($cacheKey, $namespace))) { |
64 | 64 | return true; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param string|int $ttl |
149 | 149 | * @return CacheDataFormatter|mixed |
150 | 150 | */ |
151 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
151 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
152 | 152 | { |
153 | 153 | $cacheData = $this->cacheStore->getCache($cacheKey, $namespace, $ttl); |
154 | 154 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | { |
177 | 177 | $cacheData = $this->getCache($cacheKey, $namespace); |
178 | 178 | |
179 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
179 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
180 | 180 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
181 | 181 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
182 | 182 | return true; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @param string|int $ttl |
201 | 201 | * @return void |
202 | 202 | */ |
203 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
203 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
204 | 204 | { |
205 | 205 | $this->cacheStore->putCache($cacheKey, $cacheData, $namespace, $ttl); |
206 | 206 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @param string $namespace |
224 | 224 | * @return mixed |
225 | 225 | */ |
226 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
226 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
227 | 227 | { |
228 | 228 | $renewedCache = $this->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
229 | 229 | |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | * @param Closure $callback |
243 | 243 | * @return mixed |
244 | 244 | */ |
245 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
245 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
246 | 246 | { |
247 | 247 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
248 | 248 | |
249 | - if(!empty($cachedData)) { |
|
249 | + if (!empty($cachedData)) { |
|
250 | 250 | return $cachedData; |
251 | 251 | } |
252 | 252 |