Passed
Branch main (8837c4)
by Sílvio
14:13
created
src/Service/CacheRetriever.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,20 +17,20 @@
 block discarded – undo
17 17
 class CacheRetriever
18 18
 {
19 19
     /**
20
-    * @var Cacheer
21
-    */
20
+     * @var Cacheer
21
+     */
22 22
     private Cacheer $cacheer;
23 23
 
24 24
     /**
25
-    * @var int
26
-    */
25
+     * @var int
26
+     */
27 27
     private int $foreverTTL = CacheTimeConstants::CACHE_FOREVER_TTL->value;
28 28
 
29 29
     /**
30
-    * CacheRetriever constructor.
31
-    *
32
-    * @param Cacheer $cacheer
33
-    */
30
+     * CacheRetriever constructor.
31
+     *
32
+     * @param Cacheer $cacheer
33
+     */
34 34
     public function __construct(Cacheer $cacheer)
35 35
     {
36 36
         $this->cacheer = $cacheer;
Please login to merge, or discard this patch.
src/Service/CacheMutator.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
 class CacheMutator
15 15
 {
16 16
     /**
17
-    * @var Cacheer
18
-    */
17
+     * @var Cacheer
18
+     */
19 19
     private Cacheer $cacheer;
20 20
 
21 21
     /**
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
     private int $foreverTTL = CacheTimeConstants::CACHE_FOREVER_TTL->value;
25 25
 
26 26
     /**
27
-    * CacheMutator constructor.
28
-    *
29
-    * @param Cacheer $cacheer
30
-    */
27
+     * CacheMutator constructor.
28
+     *
29
+     * @param Cacheer $cacheer
30
+     */
31 31
     public function __construct(Cacheer $cacheer)
32 32
     {
33 33
         $this->cacheer = $cacheer;
34 34
     }
35 35
 
36 36
     /**
37
-    * Adds a cache item if it does not already exist.
38
-    *
39
-    * @param string $cacheKey
40
-    * @param mixed $cacheData
41
-    * @param string $namespace
42
-    * @param int|string $ttl
43
-    * @return bool
44
-    */
37
+     * Adds a cache item if it does not already exist.
38
+     *
39
+     * @param string $cacheKey
40
+     * @param mixed $cacheData
41
+     * @param string $namespace
42
+     * @param int|string $ttl
43
+     * @return bool
44
+     */
45 45
     public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool
46 46
     {
47 47
         if (!empty($this->cacheer->getCache($cacheKey, $namespace))) {
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
     }
56 56
 
57 57
     /**
58
-    * Appends data to an existing cache item.
59
-    *
60
-    * @param string $cacheKey
61
-    * @param mixed $cacheData
62
-    * @param string $namespace
63
-    * @return bool
64
-    */
58
+     * Appends data to an existing cache item.
59
+     *
60
+     * @param string $cacheKey
61
+     * @param mixed $cacheData
62
+     * @param string $namespace
63
+     * @return bool
64
+     */
65 65
     public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool
66 66
     {
67 67
         $this->cacheer->cacheStore->appendCache($cacheKey, $cacheData, $namespace);
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
     }
72 72
 
73 73
     /**
74
-    * Clears a specific cache item.
75
-    *
76
-    * @param string $cacheKey
77
-    * @param string $namespace
78
-    * @return bool
79
-    */
74
+     * Clears a specific cache item.
75
+     *
76
+     * @param string $cacheKey
77
+     * @param string $namespace
78
+     * @return bool
79
+     */
80 80
     public function clearCache(string $cacheKey, string $namespace = ''): bool
81 81
     {
82 82
         $this->cacheer->cacheStore->clearCache($cacheKey, $namespace);
@@ -86,20 +86,20 @@  discard block
 block discarded – undo
86 86
     }
87 87
 
88 88
     /**
89
-    * Decrements a numeric cache item by a specified amount.
90
-    *
91
-    * @param string $cacheKey
92
-    * @param int $amount
93
-    * @param string $namespace
94
-    * @return bool
95
-    */
89
+     * Decrements a numeric cache item by a specified amount.
90
+     *
91
+     * @param string $cacheKey
92
+     * @param int $amount
93
+     * @param string $namespace
94
+     * @return bool
95
+     */
96 96
     public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool
97 97
     {
98 98
         return $this->increment($cacheKey, ($amount * -1), $namespace);
99 99
     }
100 100
 
101 101
     /**
102
-    * Stores a cache item forever.
102
+     * Stores a cache item forever.
103 103
      *
104 104
      * @param string $cacheKey
105 105
      * @param mixed $cacheData
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
     }
115 115
 
116 116
     /**
117
-    * Flushes the entire cache.
118
-    *
119
-    * @return bool
120
-    */
117
+     * Flushes the entire cache.
118
+     *
119
+     * @return bool
120
+     */
121 121
     public function flushCache(): bool
122 122
     {
123 123
         $this->cacheer->cacheStore->flushCache();
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     }
128 128
 
129 129
     /**
130
-    * Increments a numeric cache item by a specified amount.
130
+     * Increments a numeric cache item by a specified amount.
131 131
      *
132 132
      * @param string $cacheKey
133 133
      * @param int $amount
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
     }
167 167
 
168 168
     /**
169
-    * Puts multiple cache items in a batch.
170
-    *
171
-    * @param array $items
172
-    * @param string $namespace
173
-    * @param int $batchSize
174
-    * @return bool
175
-    */
169
+     * Puts multiple cache items in a batch.
170
+     *
171
+     * @param array $items
172
+     * @param string $namespace
173
+     * @param int $batchSize
174
+     * @return bool
175
+     */
176 176
     public function putMany(array $items, string $namespace = '', int $batchSize = 100): bool
177 177
     {
178 178
         $this->cacheer->cacheStore->putMany($items, $namespace, $batchSize);
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
     }
183 183
 
184 184
     /**
185
-    * Renews the cache item with a new TTL.
186
-    *
187
-    * @param string $cacheKey
188
-    * @param int|string $ttl
189
-    * @param string $namespace
190
-    * @return bool
191
-    */
185
+     * Renews the cache item with a new TTL.
186
+     *
187
+     * @param string $cacheKey
188
+     * @param int|string $ttl
189
+     * @param string $namespace
190
+     * @return bool
191
+     */
192 192
     public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): bool
193 193
     {
194 194
         $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace);
Please login to merge, or discard this patch.
src/Cacheer.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -72,66 +72,66 @@  discard block
 block discarded – undo
72 72
 final class Cacheer
73 73
 {
74 74
     /**
75
-    * @var string
76
-    */
75
+     * @var string
76
+     */
77 77
     private string $message;
78 78
 
79 79
     /**
80
-    * @var boolean
81
-    */
80
+     * @var boolean
81
+     */
82 82
     private bool $success;
83 83
 
84 84
     /**
85
-    * @var boolean
86
-    */
85
+     * @var boolean
86
+     */
87 87
     private bool $formatted = false;
88 88
 
89 89
     /**
90
-    * @var bool
91
-    */
90
+     * @var bool
91
+     */
92 92
     private bool $compression = false;
93 93
 
94 94
     /**
95
-    * @var string|null
96
-    */
95
+     * @var string|null
96
+     */
97 97
     private ?string $encryptionKey = null;
98 98
 
99 99
     /**
100
-    * @var CacheerInterface
101
-    */
100
+     * @var CacheerInterface
101
+     */
102 102
     public CacheerInterface $cacheStore;
103 103
 
104 104
     /**
105
-    * @var array
106
-    */
105
+     * @var array
106
+     */
107 107
     public array $options = [];
108 108
 
109 109
     /**
110
-    * @var CacheRetriever
111
-    */
110
+     * @var CacheRetriever
111
+     */
112 112
     private CacheRetriever $retriever;
113 113
 
114 114
     /**
115
-    * @var CacheMutator
116
-    */
115
+     * @var CacheMutator
116
+     */
117 117
     private CacheMutator $mutator;
118 118
 
119 119
     /**
120
-    * @var CacheConfig
121
-    */
120
+     * @var CacheConfig
121
+     */
122 122
     private CacheConfig $config;
123 123
 
124 124
     /**
125
-    * @var Cacheer|null
126
-    */
125
+     * @var Cacheer|null
126
+     */
127 127
     private static ?Cacheer $staticInstance = null;
128 128
 
129 129
 /**
130
-    * Cacheer constructor.
131
-    *
132
-    * @param array $options
133
-    * @param bool  $formatted
134
-    * @throws RuntimeException|Exceptions\CacheFileException
130
+ * Cacheer constructor.
131
+ *
132
+ * @param array $options
133
+ * @param bool  $formatted
134
+ * @throws RuntimeException|Exceptions\CacheFileException
135 135
  */
136 136
     public function __construct(array $options = [], bool $formatted = false)
137 137
     {
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-    * Enable encryption for cached data
195
-    *
196
-    * @param string $key
197
-    * @return $this
198
-    */
194
+     * Enable encryption for cached data
195
+     *
196
+     * @param string $key
197
+     * @return $this
198
+     */
199 199
     public function useEncryption(string $key): Cacheer
200 200
     {
201 201
         $this->encryptionKey = $key;
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
     }
204 204
 
205 205
     /**
206
-    * Enable or disable data compression
207
-    *
208
-    * @param bool $status
209
-    * @return $this
210
-    */
206
+     * Enable or disable data compression
207
+     *
208
+     * @param bool $status
209
+     * @return $this
210
+     */
211 211
     public function useCompression(bool $status = true): Cacheer
212 212
     {
213 213
         $this->compression = $status;
@@ -215,43 +215,43 @@  discard block
 block discarded – undo
215 215
     }
216 216
 
217 217
     /**
218
-    * Enables or disables the formatter for cache data.
219
-    * 
220
-    * @return void
221
-    */
218
+     * Enables or disables the formatter for cache data.
219
+     * 
220
+     * @return void
221
+     */
222 222
     public function useFormatter(): void
223 223
     {
224 224
         $this->formatted = !$this->formatted;
225 225
     }
226 226
 
227 227
     /**
228
-    * Validates the options provided for the Cacheer instance.
229
-    * 
230
-    * @param array $options
231
-    * @return void
232
-    */
228
+     * Validates the options provided for the Cacheer instance.
229
+     * 
230
+     * @param array $options
231
+     * @return void
232
+     */
233 233
     private function validateOptions(array $options): void
234 234
     {
235 235
         $this->options = $options;
236 236
     }
237 237
 
238 238
     /**
239
-    * Checks if the last operation was successful.
240
-    * 
241
-    * @return bool
242
-    */
239
+     * Checks if the last operation was successful.
240
+     * 
241
+     * @return bool
242
+     */
243 243
     public function isSuccess(): bool
244 244
     {
245 245
         return $this->success;
246 246
     }
247 247
 
248 248
     /**
249
-    * Sets a message for the cache operation.
250
-    *
251
-    * @param string  $message
252
-    * @param boolean $success
253
-    * @return void
254
-    */
249
+     * Sets a message for the cache operation.
250
+     *
251
+     * @param string  $message
252
+     * @param boolean $success
253
+     * @return void
254
+     */
255 255
     private function setMessage(string $message, bool $success): void
256 256
     {
257 257
         $this->message = $message;
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
     }
260 260
 
261 261
     /**
262
-    * Retrieves the message from the last operation.
263
-    * 
264
-    * @return string
265
-    */
262
+     * Retrieves the message from the last operation.
263
+     * 
264
+     * @return string
265
+     */
266 266
     public function getMessage(): string
267 267
     {
268 268
         return $this->message;
Please login to merge, or discard this patch.
src/Core/Connect.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,15 +15,15 @@  discard block
 block discarded – undo
15 15
 class Connect
16 16
 {
17 17
     /**
18
-    * Active database driver for new connections.
19
-    */
18
+     * Active database driver for new connections.
19
+     */
20 20
     public static DatabaseDriver $connection = DatabaseDriver::SQLITE;
21 21
 
22 22
     /**
23
-    * Holds the last error encountered during connection attempts.
24
-    *
25
-    * @var PDOException|null
26
-    */
23
+     * Holds the last error encountered during connection attempts.
24
+     *
25
+     * @var PDOException|null
26
+     */
27 27
     private static ?PDOException $error = null;
28 28
 
29 29
 
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
     }
66 66
 
67 67
     /**
68
-    * Gets the current connection type.
69
-    *
70
-    * @return DatabaseDriver
68
+     * Gets the current connection type.
69
+     *
70
+     * @return DatabaseDriver
71 71
      */
72 72
     public static function getConnection(): DatabaseDriver
73 73
     {
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
     }
76 76
 
77 77
     /**
78
-    * Returns the last error encountered during connection attempts.\
79
-    * 
80
-    * @return PDOException|null
81
-    */
78
+     * Returns the last error encountered during connection attempts.\
79
+     * 
80
+     * @return PDOException|null
81
+     */
82 82
     public static function getError(): ?PDOException
83 83
     {
84 84
         return self::$error;
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
      * This class is designed to be used statically, so it cannot be instantiated.
90 90
      * 
91 91
      * @return void
92
-    */    
92
+     */    
93 93
     private function __construct() {}
94 94
 
95 95
     /**
96
-    * Prevents cloning of the Connect instance.
97
-    *
98
-    * @return void
99
-    */
96
+     * Prevents cloning of the Connect instance.
97
+     *
98
+     * @return void
99
+     */
100 100
     private function __clone() {}
101 101
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
      * @return void
51 51
      * @throws ConnectionException
52 52
      */
53
-    public static function setConnection(DatabaseDriver|string $connection): void
53
+    public static function setConnection(DatabaseDriver | string $connection): void
54 54
     {
55 55
         $driver = $connection instanceof DatabaseDriver
56 56
             ? $connection
Please login to merge, or discard this patch.
src/Helpers/CacheFileHelper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
      * @return float|int
22 22
      * @throws CacheFileException
23 23
      */
24
-    public static function convertExpirationToSeconds(string $expiration): float|int
24
+    public static function convertExpirationToSeconds(string $expiration): float | int
25 25
     {
26 26
         $units = [
27 27
             'second' => CacheTimeConstants::SECOND->value,
Please login to merge, or discard this patch.
src/Helpers/CacheConfig.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@
 block discarded – undo
94 94
      * @return void
95 95
      * @throws ConnectionException
96 96
      */
97
-    public function setDatabaseConnection(DatabaseDriver|string $driver): void
97
+    public function setDatabaseConnection(DatabaseDriver | string $driver): void
98 98
     {
99 99
         Connect::setConnection($driver);
100 100
     }
Please login to merge, or discard this patch.
src/Helpers/FlushHelper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
      * @param string $identifier e.g., namespace or table name
21 21
      * @return string
22 22
      */
23
-    public static function pathFor(CacheStoreType|string $storeType, string $identifier): string
23
+    public static function pathFor(CacheStoreType | string $storeType, string $identifier): string
24 24
     {
25 25
         $store = $storeType instanceof CacheStoreType ? $storeType->value : $storeType;
26 26
         $root = EnvHelper::getRootPath();
Please login to merge, or discard this patch.
tests/Unit/RedisOptionBuilderTTLAndFlushTest.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -9,37 +9,37 @@  discard block
 block discarded – undo
9 9
 
10 10
 class RedisOptionBuilderTTLAndFlushTest extends TestCase
11 11
 {
12
-  private ?PredisClient $client = null;
12
+    private ?PredisClient $client = null;
13 13
 
14
-  protected function setUp(): void
15
-  {
14
+    protected function setUp(): void
15
+    {
16 16
     try {
17
-      PredisAutoloader::register();
18
-      $this->client = new PredisClient([
17
+        PredisAutoloader::register();
18
+        $this->client = new PredisClient([
19 19
         'scheme' => 'tcp',
20 20
         'host'   => REDIS_CONNECTION_CONFIG['REDIS_HOST'] ?? '127.0.0.1',
21 21
         'port'   => REDIS_CONNECTION_CONFIG['REDIS_PORT'] ?? 6379,
22
-      ]);
23
-      $this->client->connect();
24
-      $this->client->ping();
22
+        ]);
23
+        $this->client->connect();
24
+        $this->client->ping();
25 25
     } catch (\Throwable $e) {
26
-      $this->markTestSkipped('Redis not available: ' . $e->getMessage());
26
+        $this->markTestSkipped('Redis not available: ' . $e->getMessage());
27
+    }
27 28
     }
28
-  }
29 29
 
30
-  protected function tearDown(): void
31
-  {
30
+    protected function tearDown(): void
31
+    {
32 32
     if ($this->client) {
33
-      $this->client->disconnect();
33
+        $this->client->disconnect();
34
+    }
34 35
     }
35
-  }
36 36
 
37
-  public function test_expiration_time_from_options_sets_default_ttl()
38
-  {
37
+    public function test_expiration_time_from_options_sets_default_ttl()
38
+    {
39 39
     $options = OptionBuilder::forRedis()
40
-      ->setNamespace('app:')
41
-      ->expirationTime('1 seconds')
42
-      ->build();
40
+        ->setNamespace('app:')
41
+        ->expirationTime('1 seconds')
42
+        ->build();
43 43
 
44 44
     $cache = new Cacheer($options);
45 45
     $cache->setDriver()->useRedisDriver();
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
 
51 51
     sleep(2);
52 52
     $this->assertNull($cache->getCache($key));
53
-  }
53
+    }
54 54
 
55
-  public function test_flush_after_from_options_triggers_auto_flush()
56
-  {
55
+    public function test_flush_after_from_options_triggers_auto_flush()
56
+    {
57 57
     $options = OptionBuilder::forRedis()
58
-      ->setNamespace('app:')
59
-      ->flushAfter('1 seconds')
60
-      ->build();
58
+        ->setNamespace('app:')
59
+        ->flushAfter('1 seconds')
60
+        ->build();
61 61
 
62 62
     $flushFile = FlushHelper::pathFor('redis', 'app:');
63 63
     file_put_contents($flushFile, (string) (time() - 3600));
@@ -71,5 +71,5 @@  discard block
 block discarded – undo
71 71
     $cache = new Cacheer($options);
72 72
     $cache->setDriver()->useRedisDriver();
73 73
     $this->assertFalse((bool)$this->client?->exists('app:to_be_flushed'));
74
-  }
74
+    }
75 75
 }
Please login to merge, or discard this patch.
tests/Unit/MigrationManagerDynamicTableTest.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@  discard block
 block discarded – undo
7 7
 
8 8
 class MigrationManagerDynamicTableTest extends TestCase
9 9
 {
10
-  private ?PDO $pdo = null;
11
-  private string $table;
10
+    private ?PDO $pdo = null;
11
+    private string $table;
12 12
 
13
-  protected function setUp(): void
14
-  {
13
+    protected function setUp(): void
14
+    {
15 15
     $this->pdo = Connect::getInstance();
16 16
     $this->table = uniqid('mm_custom_table_');
17 17
     // Ensure clean start
18 18
     $this->pdo->exec("DROP TABLE IF EXISTS {$this->table}");
19
-  }
19
+    }
20 20
 
21
-  protected function tearDown(): void
22
-  {
21
+    protected function tearDown(): void
22
+    {
23 23
     if ($this->pdo) {
24
-      $this->pdo->exec("DROP TABLE IF EXISTS {$this->table}");
24
+        $this->pdo->exec("DROP TABLE IF EXISTS {$this->table}");
25
+    }
25 26
     }
26
-  }
27 27
 
28
-  public function test_migrate_creates_custom_table()
29
-  {
28
+    public function test_migrate_creates_custom_table()
29
+    {
30 30
     MigrationManager::migrate($this->pdo, $this->table);
31 31
 
32 32
     // Verify table exists (SQLite check)
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
     $stmt->execute();
51 51
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
52 52
     $this->assertEquals(['a' => 1], unserialize($row['cacheData']));
53
-  }
53
+    }
54 54
 
55
-  public function test_default_constant_table_exists()
56
-  {
55
+    public function test_default_constant_table_exists()
56
+    {
57 57
     // With boot autoload, the default CACHEER_TABLE should be created via Connect::getInstance()
58 58
     $stmt = $this->pdo?->query("SELECT name FROM sqlite_master WHERE type='table' AND name = 'cacheer_table'");
59 59
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
60 60
     $this->assertNotFalse($row);
61
-  }
61
+    }
62 62
 }
Please login to merge, or discard this patch.