Passed
Push — main ( 994ffc...08f4bd )
by Sílvio
01:02 queued 14s
created
src/CacheStore/CacheManager/FileCacheManager.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/Exceptions/CacheFileException.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
tests/Feature/OptionBuildTest.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/CacheStore/RedisCacheStore.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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');
Please login to merge, or discard this patch.
src/CacheStore/DatabaseCacheStore.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/Core/Connect.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -14,27 +14,27 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Core/ConnectionFactory.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@
 block discarded – undo
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()];
Please login to merge, or discard this patch.
src/Config/Option/Builder/OptionBuilder.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@
 block discarded – undo
12 12
 class OptionBuilder
13 13
 {
14 14
   
15
-  /**
16
-  * Creates a FileOptionBuilder instance for file-based cache options.
17
-  *
18
-  * @return FileOptionBuilder
19
-  */
20
-  public static function forFile() 
21
-  {
15
+    /**
16
+     * Creates a FileOptionBuilder instance for file-based cache options.
17
+     *
18
+     * @return FileOptionBuilder
19
+     */
20
+    public static function forFile() 
21
+    {
22 22
     return new FileOptionBuilder();
23
-  }
23
+    }
24 24
 }
Please login to merge, or discard this patch.
src/CacheStore/ArrayCacheStore.php 2 patches
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -13,341 +13,341 @@  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
-   * @param boolean
23
-   */
24
-  private bool $success = false;
25
-
26
-  /**
27
-   * @param string
28
-   */
29
-  private string $message = '';
30
-
31
-  /**
32
-   * @var CacheLogger
33
-   */
34
-  private $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
+     * @param boolean
23
+     */
24
+    private bool $success = false;
25
+
26
+    /**
27
+     * @param string
28
+     */
29
+    private string $message = '';
30
+
31
+    /**
32
+     * @var CacheLogger
33
+     */
34
+    private $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 = '')
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 = '')
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 = '')
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 = '')
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 = '')
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 = '')
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 = '')
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 = '')
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()
115
-  {
107
+    }
108
+
109
+    /**
110
+     * Flushes all cache items.
111
+     * 
112
+     * @return void
113
+     */
114
+    public function flushCache()
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
-  }
121
-
122
-  /**
123
-   * Stores a cache item permanently.
124
-   * 
125
-   * @param string $cacheKey
126
-   * @param mixed $cacheData
127
-   * @param string $namespace
128
-   * @param int|string $ttl
129
-   * @return void
130
-   */
131
-  public function forever(string $cacheKey, mixed $cacheData)
132
-  {
120
+    }
121
+
122
+    /**
123
+     * Stores a cache item permanently.
124
+     * 
125
+     * @param string $cacheKey
126
+     * @param mixed $cacheData
127
+     * @param string $namespace
128
+     * @param int|string $ttl
129
+     * @return void
130
+     */
131
+    public function forever(string $cacheKey, mixed $cacheData)
132
+    {
133 133
     $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000);
134 134
     $this->setMessage($this->getMessage(), $this->isSuccess());
135
-  }
136
-
137
-  /**
138
-   * Retrieves a single cache item.
139
-   * 
140
-   * @param string $cacheKey
141
-   * @param string $namespace
142
-   * @param int|string $ttl
143
-   * @return mixed
144
-   */
145
-  public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600)
146
-  {
135
+    }
136
+
137
+    /**
138
+     * Retrieves a single cache item.
139
+     * 
140
+     * @param string $cacheKey
141
+     * @param string $namespace
142
+     * @param int|string $ttl
143
+     * @return mixed
144
+     */
145
+    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600)
146
+    {
147 147
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
148 148
 
149 149
     if (!$this->has($cacheKey, $namespace)) {
150
-      $this->handleCacheNotFound();
151
-      return false;
150
+        $this->handleCacheNotFound();
151
+        return false;
152 152
     }
153 153
 
154 154
     $cacheData = $this->arrayStore[$arrayStoreKey];
155 155
     if ($this->isExpired($cacheData)) {
156
-      $this->handleCacheExpired($arrayStoreKey);
157
-      return false;
156
+        $this->handleCacheExpired($arrayStoreKey);
157
+        return false;
158 158
     }
159 159
 
160 160
     $this->setMessage("Cache retrieved successfully", true);
161 161
     $this->logger->debug("{$this->getMessage()} from array driver.");
162 162
     return $this->serialize($cacheData['cacheData'], false);
163
-  }
164
-
165
-  /**
166
-   * Verify if the cache is expired.
167
-   * 
168
-   * @param array $cacheData
169
-   * @return bool
170
-   */
171
-  private function isExpired(array $cacheData): bool
172
-  {
163
+    }
164
+
165
+    /**
166
+     * Verify if the cache is expired.
167
+     * 
168
+     * @param array $cacheData
169
+     * @return bool
170
+     */
171
+    private function isExpired(array $cacheData): bool
172
+    {
173 173
     $expirationTime = $cacheData['expirationTime'] ?? 0;
174 174
     $now = time();
175 175
     return $expirationTime !== 0 && $now >= $expirationTime;
176
-  }
177
-
178
-  /**
179
-   * Handles the case when cache data is not found.
180
-   * 
181
-   * @return void
182
-   */
183
-  private function handleCacheNotFound()
184
-  {
176
+    }
177
+
178
+    /**
179
+     * Handles the case when cache data is not found.
180
+     * 
181
+     * @return void
182
+     */
183
+    private function handleCacheNotFound()
184
+    {
185 185
     $this->setMessage("cacheData not found, does not exists or expired", false);
186 186
     $this->logger->debug("{$this->getMessage()} from array driver.");
187
-  }
188
-
189
-  /**
190
-   * Handles the case when cache data has expired.
191
-   * 
192
-   * @param string $arrayStoreKey
193
-   * @return void
194
-   */
195
-  private function handleCacheExpired(string $arrayStoreKey)
196
-  {
187
+    }
188
+
189
+    /**
190
+     * Handles the case when cache data has expired.
191
+     * 
192
+     * @param string $arrayStoreKey
193
+     * @return void
194
+     */
195
+    private function handleCacheExpired(string $arrayStoreKey)
196
+    {
197 197
     $parts = explode(':', $arrayStoreKey, 2);
198 198
     if (count($parts) === 2) {
199
-      list($np, $key) = $parts;
199
+        list($np, $key) = $parts;
200 200
     } else {
201
-      $np = '';
202
-      $key = $arrayStoreKey;
201
+        $np = '';
202
+        $key = $arrayStoreKey;
203 203
     }
204 204
     $this->clearCache($key, $np);
205 205
     $this->setMessage("cacheKey: {$key} has expired.", false);
206 206
     $this->logger->debug("{$this->getMessage()} from array driver.");
207
-  }
208
-
209
-  /**
210
-   * Gets all items in a specific namespace.
211
-   * 
212
-   * @param string $namespace
213
-   * @return array
214
-   */
215
-  public function getAll(string $namespace = '')
216
-  {
207
+    }
208
+
209
+    /**
210
+     * Gets all items in a specific namespace.
211
+     * 
212
+     * @param string $namespace
213
+     * @return array
214
+     */
215
+    public function getAll(string $namespace = '')
216
+    {
217 217
     $results = [];
218 218
     foreach ($this->arrayStore as $key => $data) {
219
-      if (strpos($key, $namespace . ':') === 0 || empty($namespace)) {
219
+        if (strpos($key, $namespace . ':') === 0 || empty($namespace)) {
220 220
         $results[$key] = $this->serialize($data['cacheData'], false);
221
-      }
221
+        }
222 222
     }
223 223
     return $results;
224
-  }
225
-
226
-  /**
227
-   * Retrieves multiple cache items by their keys.
228
-   * 
229
-   * @param array $cacheKeys
230
-   * @param string $namespace
231
-   * @param string|int $ttl
232
-   * @return array
233
-   */
234
-  public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600)
235
-  {
224
+    }
225
+
226
+    /**
227
+     * Retrieves multiple cache items by their keys.
228
+     * 
229
+     * @param array $cacheKeys
230
+     * @param string $namespace
231
+     * @param string|int $ttl
232
+     * @return array
233
+     */
234
+    public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600)
235
+    {
236 236
     $results = [];
237 237
     foreach ($cacheKeys as $cacheKey) {
238
-      $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl);
238
+        $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl);
239 239
     }
240 240
     return $results;
241
-  }
242
-
243
-  /**
244
-   * Checks if a cache item exists.
245
-   * 
246
-   * @param string $cacheKey
247
-   * @param string $namespace
248
-   * @return bool
249
-   */
250
-  public function has(string $cacheKey, string $namespace = '')
251
-  {
241
+    }
242
+
243
+    /**
244
+     * Checks if a cache item exists.
245
+     * 
246
+     * @param string $cacheKey
247
+     * @param string $namespace
248
+     * @return bool
249
+     */
250
+    public function has(string $cacheKey, string $namespace = '')
251
+    {
252 252
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
253 253
     return isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime'];
254
-  }
255
-
256
-  /**
257
-   * Increments a cache item by a specified amount.
258
-   * 
259
-   * @param string $cacheKey
260
-   * @param int $amount
261
-   * @param string $namespace
262
-   * @return bool
263
-   */
264
-  public function increment(string $cacheKey, int $amount = 1, string $namespace = '')
265
-  {
254
+    }
255
+
256
+    /**
257
+     * Increments a cache item by a specified amount.
258
+     * 
259
+     * @param string $cacheKey
260
+     * @param int $amount
261
+     * @param string $namespace
262
+     * @return bool
263
+     */
264
+    public function increment(string $cacheKey, int $amount = 1, string $namespace = '')
265
+    {
266 266
     $cacheData = $this->getCache($cacheKey, $namespace);
267 267
 
268 268
     if(!empty($cacheData) && is_numeric($cacheData)) {
269
-      $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
270
-      $this->setMessage($this->getMessage(), $this->isSuccess());
271
-      return true;
269
+        $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
270
+        $this->setMessage($this->getMessage(), $this->isSuccess());
271
+        return true;
272 272
     }
273 273
 
274 274
     return false;
275
-  }
276
-
277
-  /**
278
-   * Checks if the operation was successful.
279
-   * 
280
-   * @return boolean
281
-   */
282
-  public function isSuccess()
283
-  {
275
+    }
276
+
277
+    /**
278
+     * Checks if the operation was successful.
279
+     * 
280
+     * @return boolean
281
+     */
282
+    public function isSuccess()
283
+    {
284 284
     return $this->success;
285
-  }
286
-
287
-  /**
288
-   * Gets the last message.
289
-   * 
290
-   * @return string
291
-   */
292
-  public function getMessage()
293
-  {
285
+    }
286
+
287
+    /**
288
+     * Gets the last message.
289
+     * 
290
+     * @return string
291
+     */
292
+    public function getMessage()
293
+    {
294 294
     return $this->message;
295
-  }
296
-
297
-  /**
298
-   * Stores an item in the cache with a specific TTL.
299
-   * 
300
-   * @param string $cacheKey
301
-   * @param mixed $cacheData
302
-   * @param string $namespace
303
-   * @param int|string $ttl
304
-   * @return bool
305
-   */
306
-  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
307
-  {
295
+    }
296
+
297
+    /**
298
+     * Stores an item in the cache with a specific TTL.
299
+     * 
300
+     * @param string $cacheKey
301
+     * @param mixed $cacheData
302
+     * @param string $namespace
303
+     * @param int|string $ttl
304
+     * @return bool
305
+     */
306
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
307
+    {
308 308
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
309 309
 
310 310
     $this->arrayStore[$arrayStoreKey] = [
311
-      'cacheData' => serialize($cacheData),
312
-      'expirationTime' => time() + $ttl
311
+        'cacheData' => serialize($cacheData),
312
+        'expirationTime' => time() + $ttl
313 313
     ];
314 314
 
315 315
     $this->setMessage("Cache stored successfully", true);
316 316
     $this->logger->debug("{$this->getMessage()} from Array driver.");
317 317
     return true;
318
-  }
319
-
320
-  /**
321
-   * Stores multiple items in the cache in batches.
322
-   * 
323
-   * @param array $items
324
-   * @param string $namespace
325
-   * @param int $batchSize
326
-   * @return void
327
-   */
328
-  public function putMany(array $items, string $namespace = '', int $batchSize = 100)
329
-  {
318
+    }
319
+
320
+    /**
321
+     * Stores multiple items in the cache in batches.
322
+     * 
323
+     * @param array $items
324
+     * @param string $namespace
325
+     * @param int $batchSize
326
+     * @return void
327
+     */
328
+    public function putMany(array $items, string $namespace = '', int $batchSize = 100)
329
+    {
330 330
     $chunks = array_chunk($items, $batchSize, true);
331 331
 
332 332
     foreach ($chunks as $chunk) {
333
-      foreach ($chunk as $key => $data) {
334
-          $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
333
+        foreach ($chunk as $key => $data) {
334
+            $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
335
+        }
335 336
         }
336
-      }
337 337
     $this->setMessage("{$this->getMessage()}", $this->isSuccess());
338 338
     $this->logger->debug("{$this->getMessage()} from Array driver.");
339
-  }
340
-
341
-  /**
342
-   * Renews the expiration time of a cache item.
343
-   * 
344
-   * @param string $cacheKey
345
-   * @param string|int $ttl
346
-   * @param string $namespace
347
-   * @return void
348
-   */
349
-  public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '')
350
-  {
339
+    }
340
+
341
+    /**
342
+     * Renews the expiration time of a cache item.
343
+     * 
344
+     * @param string $cacheKey
345
+     * @param string|int $ttl
346
+     * @param string $namespace
347
+     * @return void
348
+     */
349
+    public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '')
350
+    {
351 351
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
352 352
 
353 353
     if (isset($this->arrayStore[$arrayStoreKey])) {
@@ -355,31 +355,31 @@  discard block
 block discarded – undo
355 355
         $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds;
356 356
         $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true);
357 357
         $this->logger->debug("{$this->getMessage()} from array driver.");
358
-      }
359
-  }
360
-
361
-  /**
362
-   * Sets a message and its success status.
363
-   * 
364
-   * @param string  $message
365
-   * @param boolean $success
366
-   * @return void
367
-   */
368
-  private function setMessage(string $message, bool $success)
369
-  {
358
+        }
359
+    }
360
+
361
+    /**
362
+     * Sets a message and its success status.
363
+     * 
364
+     * @param string  $message
365
+     * @param boolean $success
366
+     * @return void
367
+     */
368
+    private function setMessage(string $message, bool $success)
369
+    {
370 370
     $this->message = $message;
371 371
     $this->success = $success;
372
-  }
373
-
374
-  /**
375
-   * Serializes or unserializes data based on the flag.
376
-   * 
377
-   * @param mixed $data
378
-   * @param bool $serialize
379
-   * @return mixed
380
-   */
381
-  private function serialize(mixed $data, bool $serialize = true)
382
-  {
372
+    }
373
+
374
+    /**
375
+     * Serializes or unserializes data based on the flag.
376
+     * 
377
+     * @param mixed $data
378
+     * @param bool $serialize
379
+     * @return mixed
380
+     */
381
+    private function serialize(mixed $data, bool $serialize = true)
382
+    {
383 383
     return $serialize ? serialize($data) : unserialize($data);
384
-  }
384
+    }
385 385
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
    * @param int|string $ttl
143 143
    * @return mixed
144 144
    */
145
-  public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600)
145
+  public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600)
146 146
   {
147 147
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
148 148
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
    * @param string|int $ttl
232 232
    * @return array
233 233
    */
234
-  public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600)
234
+  public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600)
235 235
   {
236 236
     $results = [];
237 237
     foreach ($cacheKeys as $cacheKey) {
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
   {
266 266
     $cacheData = $this->getCache($cacheKey, $namespace);
267 267
 
268
-    if(!empty($cacheData) && is_numeric($cacheData)) {
268
+    if (!empty($cacheData) && is_numeric($cacheData)) {
269 269
       $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
270 270
       $this->setMessage($this->getMessage(), $this->isSuccess());
271 271
       return true;
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
    * @param int|string $ttl
304 304
    * @return bool
305 305
    */
306
-  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
306
+  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600)
307 307
   {
308 308
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
309 309
 
@@ -346,12 +346,12 @@  discard block
 block discarded – undo
346 346
    * @param string $namespace
347 347
    * @return void
348 348
    */
349
-  public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '')
349
+  public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = '')
350 350
   {
351 351
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
352 352
 
353 353
     if (isset($this->arrayStore[$arrayStoreKey])) {
354
-        $ttlSeconds = is_numeric($ttl) ? (int) $ttl : strtotime($ttl) - time();
354
+        $ttlSeconds = is_numeric($ttl) ? (int)$ttl : strtotime($ttl) - time();
355 355
         $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds;
356 356
         $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true);
357 357
         $this->logger->debug("{$this->getMessage()} from array driver.");
Please login to merge, or discard this patch.