@@ -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); |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Retrieves cache data from the database. |
|
64 | - * |
|
65 | - * @param string $cacheKey |
|
66 | - * @param string $namespace |
|
67 | - * @return mixed |
|
68 | - */ |
|
63 | + * Retrieves cache data from the database. |
|
64 | + * |
|
65 | + * @param string $cacheKey |
|
66 | + * @param string $namespace |
|
67 | + * @return mixed |
|
68 | + */ |
|
69 | 69 | public function retrieve(string $cacheKey, string $namespace = '') |
70 | 70 | { |
71 | 71 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Retrieves multiple cache items by their keys. |
|
89 | - * @param array $cacheKeys |
|
90 | - * @param string $namespace |
|
91 | - * @return array |
|
92 | - */ |
|
88 | + * Retrieves multiple cache items by their keys. |
|
89 | + * @param array $cacheKeys |
|
90 | + * @param string $namespace |
|
91 | + * @return array |
|
92 | + */ |
|
93 | 93 | public function getAll(string $namespace = '') |
94 | 94 | { |
95 | 95 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Get Update query based on the database driver. |
|
114 | - * |
|
115 | - * @return string |
|
116 | - */ |
|
113 | + * Get Update query based on the database driver. |
|
114 | + * |
|
115 | + * @return string |
|
116 | + */ |
|
117 | 117 | private function getUpdateQueryWithDriver() |
118 | 118 | { |
119 | 119 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | - * Get Delete query based on the database driver. |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
127 | + * Get Delete query based on the database driver. |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | 131 | private function getDeleteQueryWithDriver() |
132 | 132 | { |
133 | 133 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | - * Updates an existing cache item in the database. |
|
142 | - * |
|
143 | - * @param string $cacheKey |
|
144 | - * @param mixed $cacheData |
|
145 | - * @param string $namespace |
|
146 | - * @return bool |
|
147 | - */ |
|
141 | + * Updates an existing cache item in the database. |
|
142 | + * |
|
143 | + * @param string $cacheKey |
|
144 | + * @param mixed $cacheData |
|
145 | + * @param string $namespace |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | 148 | public function update(string $cacheKey, mixed $cacheData, string $namespace = '') |
149 | 149 | { |
150 | 150 | $query = $this->getUpdateQueryWithDriver(); |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | - * Clears a specific cache item from the database. |
|
162 | - * |
|
163 | - * @param string $cacheKey |
|
164 | - * @param string $namespace |
|
165 | - * @return bool |
|
166 | - */ |
|
161 | + * Clears a specific cache item from the database. |
|
162 | + * |
|
163 | + * @param string $cacheKey |
|
164 | + * @param string $namespace |
|
165 | + * @return bool |
|
166 | + */ |
|
167 | 167 | public function clear(string $cacheKey, string $namespace = '') |
168 | 168 | { |
169 | 169 | $query = $this->getDeleteQueryWithDriver(); |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Gets the query to renew the expiration time of a cache item based on the database driver. |
|
180 | - * |
|
181 | - * @return string |
|
182 | - */ |
|
179 | + * Gets the query to renew the expiration time of a cache item based on the database driver. |
|
180 | + * |
|
181 | + * @return string |
|
182 | + */ |
|
183 | 183 | private function getRenewExpirationQueryWithDriver(): string |
184 | 184 | { |
185 | 185 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | - * Checks if a cache item is valid based on its key, namespace, and current time. |
|
198 | - * |
|
199 | - * @param string $cacheKey |
|
200 | - * @param string $namespace |
|
201 | - * @param string $currentTime |
|
202 | - * @return bool |
|
203 | - */ |
|
197 | + * Checks if a cache item is valid based on its key, namespace, and current time. |
|
198 | + * |
|
199 | + * @param string $cacheKey |
|
200 | + * @param string $namespace |
|
201 | + * @param string $currentTime |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | 204 | private function hasValidCache(string $cacheKey, string $namespace, string $currentTime): bool |
205 | 205 | { |
206 | 206 | $stmt = $this->connection->prepare( |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Renews the expiration time of a cache item. |
|
220 | - * |
|
221 | - * @param string $cacheKey |
|
222 | - * @param string|int $ttl |
|
223 | - * @param string $namespace |
|
224 | - * @return bool |
|
225 | - */ |
|
219 | + * Renews the expiration time of a cache item. |
|
220 | + * |
|
221 | + * @param string $cacheKey |
|
222 | + * @param string|int $ttl |
|
223 | + * @param string $namespace |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | 226 | public function renew(string $cacheKey, string|int $ttl, string $namespace = '') |
227 | 227 | { |
228 | 228 | $currentTime = date('Y-m-d H:i:s'); |
@@ -242,32 +242,32 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Flushes all cache items from the database. |
|
246 | - * |
|
247 | - * @return bool |
|
248 | - */ |
|
245 | + * Flushes all cache items from the database. |
|
246 | + * |
|
247 | + * @return bool |
|
248 | + */ |
|
249 | 249 | public function flush() |
250 | 250 | { |
251 | 251 | return $this->connection->exec("DELETE FROM cacheer_table") !== false; |
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
255 | - * Serializes or unserializes data based on the provided flag. |
|
256 | - * |
|
257 | - * @param mixed $data |
|
258 | - * @return string |
|
259 | - */ |
|
255 | + * Serializes or unserializes data based on the provided flag. |
|
256 | + * |
|
257 | + * @param mixed $data |
|
258 | + * @return string |
|
259 | + */ |
|
260 | 260 | private function serialize(mixed $data, bool $serialize = true) |
261 | 261 | { |
262 | 262 | return $serialize ? serialize($data) : unserialize($data); |
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | - * Gets the current date and time based on the database driver. |
|
267 | - * |
|
268 | - * @param string $driver |
|
269 | - * @return string |
|
270 | - */ |
|
266 | + * Gets the current date and time based on the database driver. |
|
267 | + * |
|
268 | + * @param string $driver |
|
269 | + * @return string |
|
270 | + */ |
|
271 | 271 | private function getCurrentDateTime(string $driver) |
272 | 272 | { |
273 | 273 | return ($driver === 'sqlite') ? "DATETIME('now', 'localtime')" : "NOW()"; |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | /** |
18 | - * @param string $dir |
|
19 | - * @return void |
|
20 | - */ |
|
18 | + * @param string $dir |
|
19 | + * @return void |
|
20 | + */ |
|
21 | 21 | public function createDirectory(string $dir) |
22 | 22 | { |
23 | 23 | if ((!file_exists($dir) || !is_dir($dir)) && !mkdir($dir, 0755, true)) { |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | - * @param string $filename |
|
30 | - * @param string $data |
|
31 | - * @return void |
|
32 | - */ |
|
29 | + * @param string $filename |
|
30 | + * @param string $data |
|
31 | + * @return void |
|
32 | + */ |
|
33 | 33 | public function writeFile(string $filename, string $data) |
34 | 34 | { |
35 | 35 | if (!@file_put_contents($filename, $data, LOCK_EX)) { |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * @param string $filename |
|
42 | - * @return string |
|
43 | - */ |
|
41 | + * @param string $filename |
|
42 | + * @return string |
|
43 | + */ |
|
44 | 44 | public function readFile(string $filename) |
45 | 45 | { |
46 | 46 | if (!$this->fileExists($filename)) { |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * @param string $filename |
|
54 | - * @return bool |
|
55 | - */ |
|
53 | + * @param string $filename |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | 56 | public function fileExists(string $filename) |
57 | 57 | { |
58 | 58 | return file_exists($filename); |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * @param string $filename |
|
63 | - * @return void |
|
64 | - */ |
|
62 | + * @param string $filename |
|
63 | + * @return void |
|
64 | + */ |
|
65 | 65 | public function removeFile(string $filename) |
66 | 66 | { |
67 | 67 | if (file_exists($filename)) { |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * @param string $dir |
|
74 | - * @return void |
|
75 | - */ |
|
73 | + * @param string $dir |
|
74 | + * @return void |
|
75 | + */ |
|
76 | 76 | public function clearDirectory(string $dir) |
77 | 77 | { |
78 | 78 | $iterator = new RecursiveIteratorIterator( |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * @param mixed $data |
|
90 | - * @param bool $serialize |
|
91 | - */ |
|
89 | + * @param mixed $data |
|
90 | + * @param bool $serialize |
|
91 | + */ |
|
92 | 92 | public function serialize(mixed $data, bool $serialize = true) |
93 | 93 | { |
94 | 94 | if($serialize) { |
@@ -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); |
@@ -58,7 +58,7 @@ |
||
58 | 58 | */ |
59 | 59 | public function toJson(int $options = 0) |
60 | 60 | { |
61 | - return parent::toJson($options); |
|
61 | + return parent::toJson($options); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 |
@@ -7,26 +7,26 @@ discard block |
||
7 | 7 | class OptionBuildTest extends TestCase |
8 | 8 | { |
9 | 9 | |
10 | - private $cache; |
|
11 | - private $cacheDir; |
|
10 | + private $cache; |
|
11 | + private $cacheDir; |
|
12 | 12 | |
13 | - protected function setUp(): void |
|
14 | - { |
|
13 | + protected function setUp(): void |
|
14 | + { |
|
15 | 15 | $this->cacheDir = __DIR__ . '/cache'; |
16 | 16 | if (!file_exists($this->cacheDir) || !is_dir($this->cacheDir)) { |
17 | - mkdir($this->cacheDir, 0755, true); |
|
17 | + mkdir($this->cacheDir, 0755, true); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | $this->cache = new Cacheer(); |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - protected function tearDown(): void |
|
24 | - { |
|
23 | + protected function tearDown(): void |
|
24 | + { |
|
25 | 25 | $this->cache->flushCache(); |
26 | - } |
|
26 | + } |
|
27 | 27 | |
28 | - public function test_it_can_set_cache_directory() |
|
29 | - { |
|
28 | + public function test_it_can_set_cache_directory() |
|
29 | + { |
|
30 | 30 | $cacheDir = __DIR__ . "/cache"; |
31 | 31 | |
32 | 32 | $options = OptionBuilder::forFile() |
@@ -35,23 +35,23 @@ discard block |
||
35 | 35 | |
36 | 36 | $this->assertArrayHasKey('cacheDir', $options); |
37 | 37 | $this->assertEquals($cacheDir, $options['cacheDir']); |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - public function test_it_can_set_expiration_time() |
|
41 | + public function test_it_can_set_expiration_time() |
|
42 | 42 | { |
43 | 43 | |
44 | - $options = OptionBuilder::forFile() |
|
45 | - ->expirationTime('2 hours') |
|
46 | - ->build(); |
|
44 | + $options = OptionBuilder::forFile() |
|
45 | + ->expirationTime('2 hours') |
|
46 | + ->build(); |
|
47 | 47 | |
48 | - $this->assertArrayHasKey('expirationTime', $options); |
|
49 | - $this->assertEquals('2 hours', $options['expirationTime']); |
|
48 | + $this->assertArrayHasKey('expirationTime', $options); |
|
49 | + $this->assertEquals('2 hours', $options['expirationTime']); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function test_it_can_set_flush_after() |
53 | 53 | { |
54 | - $options = OptionBuilder::forFile() |
|
54 | + $options = OptionBuilder::forFile() |
|
55 | 55 | ->flushAfter('11 seconds') |
56 | 56 | ->build(); |
57 | 57 | |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | |
62 | 62 | public function test_it_can_set_multiple_options_together() |
63 | 63 | { |
64 | - $cacheDir = __DIR__ . "/cache"; |
|
64 | + $cacheDir = __DIR__ . "/cache"; |
|
65 | 65 | |
66 | - $options = OptionBuilder::forFile() |
|
66 | + $options = OptionBuilder::forFile() |
|
67 | 67 | ->dir($cacheDir) |
68 | 68 | ->expirationTime('1 day') |
69 | 69 | ->flushAfter('30 minutes') |
@@ -76,41 +76,41 @@ discard block |
||
76 | 76 | ], $options); |
77 | 77 | } |
78 | 78 | |
79 | - public function test_it_allows_setting_expiration_time_with_timebuilder() |
|
79 | + public function test_it_allows_setting_expiration_time_with_timebuilder() |
|
80 | 80 | { |
81 | - $options = OptionBuilder::forFile()->expirationTime()->week(1)->build(); |
|
82 | - $this->assertArrayHasKey('expirationTime', $options); |
|
83 | - $this->assertEquals('1 weeks', $options['expirationTime']); |
|
81 | + $options = OptionBuilder::forFile()->expirationTime()->week(1)->build(); |
|
82 | + $this->assertArrayHasKey('expirationTime', $options); |
|
83 | + $this->assertEquals('1 weeks', $options['expirationTime']); |
|
84 | 84 | } |
85 | 85 | |
86 | - public function test_it_allows_setting_flush_after_with_timebuilder() |
|
87 | - { |
|
86 | + public function test_it_allows_setting_flush_after_with_timebuilder() |
|
87 | + { |
|
88 | 88 | $options = OptionBuilder::forFile()->flushAfter()->second(10)->build(); |
89 | 89 | $this->assertArrayHasKey('flushAfter', $options); |
90 | 90 | $this->assertEquals('10 seconds', $options['flushAfter']); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - public function test_it_can_set_multiple_options_together_with_timebuilder() |
|
94 | - { |
|
93 | + public function test_it_can_set_multiple_options_together_with_timebuilder() |
|
94 | + { |
|
95 | 95 | $cacheDir = __DIR__ . "/cache"; |
96 | 96 | $options = OptionBuilder::forFile() |
97 | - ->dir($cacheDir) |
|
98 | - ->expirationTime()->week(1) |
|
99 | - ->flushAfter()->minute(10) |
|
100 | - ->build(); |
|
97 | + ->dir($cacheDir) |
|
98 | + ->expirationTime()->week(1) |
|
99 | + ->flushAfter()->minute(10) |
|
100 | + ->build(); |
|
101 | 101 | |
102 | 102 | $this->assertEquals([ |
103 | 103 | 'cacheDir' => $cacheDir, |
104 | 104 | 'expirationTime' => '1 weeks', |
105 | 105 | 'flushAfter' => '10 minutes', |
106 | 106 | ], $options); |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - public function test_it_returns_empty_array_when_no_options_are_set() |
|
110 | - { |
|
109 | + public function test_it_returns_empty_array_when_no_options_are_set() |
|
110 | + { |
|
111 | 111 | $options = OptionBuilder::forFile()->build(); |
112 | 112 | $this->assertIsArray($options); |
113 | 113 | $this->assertEmpty($options); |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -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); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param string|int $ttl |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
142 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
143 | 143 | { |
144 | 144 | $results = []; |
145 | 145 | foreach ($cacheKeys as $cacheKey) { |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | * @param string|int|null $ttl |
228 | 228 | * @return mixed |
229 | 229 | */ |
230 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null) |
|
230 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int | null $ttl = null) |
|
231 | 231 | { |
232 | 232 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
233 | 233 | $serializedData = CacheRedisHelper::serialize($cacheData); |
234 | 234 | |
235 | - $result = $ttl ? $this->redis->setex($cacheFullKey, (int) $ttl, $serializedData) |
|
235 | + $result = $ttl ? $this->redis->setex($cacheFullKey, (int)$ttl, $serializedData) |
|
236 | 236 | : $this->redis->set($cacheFullKey, $serializedData); |
237 | 237 | |
238 | 238 | if ($result) { |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @param string $namespace |
270 | 270 | * @return void |
271 | 271 | */ |
272 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
272 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
273 | 273 | { |
274 | 274 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
275 | 275 | $dump = $this->getDump($cacheFullKey); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @param mixed $dump |
298 | 298 | * @return bool |
299 | 299 | */ |
300 | - private function restoreKey(string $fullKey, string|int $ttl, mixed $dump) |
|
300 | + private function restoreKey(string $fullKey, string | int $ttl, mixed $dump) |
|
301 | 301 | { |
302 | 302 | try { |
303 | 303 | $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |
@@ -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) { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param string|int $ttl |
118 | 118 | * @return array |
119 | 119 | */ |
120 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
120 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
121 | 121 | { |
122 | 122 | $cacheData = []; |
123 | 123 | foreach ($cacheKeys as $cacheKey) { |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | * @param string|int $ttl |
191 | 191 | * @return bool |
192 | 192 | */ |
193 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
193 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
194 | 194 | { |
195 | - if($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)){ |
|
195 | + if ($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)) { |
|
196 | 196 | $this->logger->debug("{$this->getMessage()} from database driver."); |
197 | 197 | return true; |
198 | 198 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | private function processBatchItems(array $batchItems, string $namespace) |
225 | 225 | { |
226 | - foreach($batchItems as $item) { |
|
226 | + foreach ($batchItems as $item) { |
|
227 | 227 | CacheDatabaseHelper::validateCacheItem($item); |
228 | 228 | $cacheKey = $item['cacheKey']; |
229 | 229 | $cacheData = $item['cacheData']; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param string $namespace |
239 | 239 | * @return bool |
240 | 240 | */ |
241 | - private function renew(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
241 | + private function renew(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
242 | 242 | { |
243 | 243 | $cacheData = $this->getCache($cacheKey, $namespace); |
244 | 244 | if ($cacheData) { |
@@ -281,10 +281,10 @@ discard block |
||
281 | 281 | * @param integer $ttl |
282 | 282 | * @return bool |
283 | 283 | */ |
284 | - private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
284 | + private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
285 | 285 | { |
286 | 286 | $data = $this->cacheRepository->store($cacheKey, $cacheData, $namespace, $ttl); |
287 | - if($data) { |
|
287 | + if ($data) { |
|
288 | 288 | $this->setMessage("Cache Stored Successfully", true); |
289 | 289 | return true; |
290 | 290 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | private function updateCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
302 | 302 | { |
303 | 303 | $data = $this->cacheRepository->update($cacheKey, $cacheData, $namespace); |
304 | - if($data) { |
|
304 | + if ($data) { |
|
305 | 305 | $this->setMessage("Cache updated successfully.", true); |
306 | 306 | return true; |
307 | 307 | } |
@@ -14,27 +14,27 @@ discard block |
||
14 | 14 | class Connect |
15 | 15 | { |
16 | 16 | /** |
17 | - * The default connection type. |
|
18 | - * Currently, it supports 'mysql', 'sqlite', and 'pgsql'. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
17 | + * The default connection type. |
|
18 | + * Currently, it supports 'mysql', 'sqlite', and 'pgsql'. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | 22 | public static string $connection = 'sqlite'; |
23 | 23 | |
24 | 24 | /** |
25 | - * Holds the last error encountered during connection attempts. |
|
26 | - * |
|
27 | - * @var PDOException|null |
|
28 | - */ |
|
25 | + * Holds the last error encountered during connection attempts. |
|
26 | + * |
|
27 | + * @var PDOException|null |
|
28 | + */ |
|
29 | 29 | private static ?PDOException $error = null; |
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
33 | - * Creates a new PDO instance based on the specified database configuration. |
|
34 | - * |
|
35 | - * @param array|null $database |
|
36 | - * @return PDO|null |
|
37 | - */ |
|
33 | + * Creates a new PDO instance based on the specified database configuration. |
|
34 | + * |
|
35 | + * @param array|null $database |
|
36 | + * @return PDO|null |
|
37 | + */ |
|
38 | 38 | public static function getInstance(?array $database = null) |
39 | 39 | { |
40 | 40 | $pdo = ConnectionFactory::createConnection($database); |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | - * Sets the connection type for the database. |
|
49 | - * |
|
50 | - * @param string $connection |
|
51 | - * @return void |
|
52 | - */ |
|
48 | + * Sets the connection type for the database. |
|
49 | + * |
|
50 | + * @param string $connection |
|
51 | + * @return void |
|
52 | + */ |
|
53 | 53 | public static function setConnection(string $connection) |
54 | 54 | { |
55 | 55 | $drivers = ['mysql', 'sqlite', 'pgsql']; |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Gets the current connection type. |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
63 | + * Gets the current connection type. |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | 67 | public static function getConnection() |
68 | 68 | { |
69 | 69 | return self::$connection; |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * Returns the last error encountered during connection attempts.\ |
|
74 | - * |
|
75 | - * @return PDOException|null |
|
76 | - */ |
|
73 | + * Returns the last error encountered during connection attempts.\ |
|
74 | + * |
|
75 | + * @return PDOException|null |
|
76 | + */ |
|
77 | 77 | public static function getError() |
78 | 78 | { |
79 | 79 | return self::$error; |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * This class is designed to be used statically, so it cannot be instantiated. |
85 | 85 | * |
86 | 86 | * @return void |
87 | - */ |
|
87 | + */ |
|
88 | 88 | private function __construct() {} |
89 | 89 | |
90 | 90 | /** |
91 | - * Prevents cloning of the Connect instance. |
|
92 | - * |
|
93 | - * @return void |
|
94 | - */ |
|
91 | + * Prevents cloning of the Connect instance. |
|
92 | + * |
|
93 | + * @return void |
|
94 | + */ |
|
95 | 95 | private function __clone() {} |
96 | 96 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | /** |
18 | - * Creates a new PDO instance based on the specified database configuration. |
|
19 | - * |
|
20 | - * @param array|null $database |
|
21 | - * @return PDO|null |
|
22 | - */ |
|
18 | + * Creates a new PDO instance based on the specified database configuration. |
|
19 | + * |
|
20 | + * @param array|null $database |
|
21 | + * @return PDO|null |
|
22 | + */ |
|
23 | 23 | public static function createConnection(?array $database = null) |
24 | 24 | { |
25 | 25 | $dbConf = $database ?? CACHEER_DATABASE_CONFIG[Connect::getConnection()]; |
@@ -52,7 +52,7 @@ discard block |
||
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 |
||
62 | 62 | * @param string|int $ttl Lifetime in seconds (default: 3600) |
63 | 63 | * @return CacheDataFormatter 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 |
||
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. |