Passed
Pull Request — main (#27)
by Sílvio
02:44
created
tests/Unit/RedisCacheStoreTest.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -7,27 +7,27 @@  discard block
 block discarded – undo
7 7
 class RedisCacheStoreTest extends TestCase
8 8
 {
9 9
 
10
-  /** @var Cacheer */
11
-  private $cache;
10
+    /** @var Cacheer */
11
+    private $cache;
12 12
 
13
-  protected function setUp(): void
14
-  {
13
+    protected function setUp(): void
14
+    {
15 15
     $this->cache = new Cacheer();
16 16
     $this->cache->setDriver()->useRedisDriver();
17
-  }
17
+    }
18 18
 
19
-  protected function tearDown(): void
20
-  {
19
+    protected function tearDown(): void
20
+    {
21 21
     $this->cache->flushCache();
22
-  }
22
+    }
23 23
 
24
-  public function testUsingRedisDriverSetsProperInstance()
25
-  {
24
+    public function testUsingRedisDriverSetsProperInstance()
25
+    {
26 26
     $this->assertInstanceOf(RedisCacheStore::class, $this->cache->cacheStore);
27
-  }
27
+    }
28 28
 
29
-  public function testPutCacheInRedis()
30
-  {
29
+    public function testPutCacheInRedis()
30
+    {
31 31
     $cacheKey = 'test_key';
32 32
     $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer'];
33 33
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
     $this->assertNotEmpty($this->cache->getCache($cacheKey));
38 38
     $this->assertEquals($cacheData, $this->cache->getCache($cacheKey));
39 39
 
40
-  }
40
+    }
41 41
 
42
-  public function testGetCacheFromRedis()
43
-  {
42
+    public function testGetCacheFromRedis()
43
+    {
44 44
     $cacheKey = 'test_key';
45 45
     $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer'];
46 46
 
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
     $data = $this->cache->getCache($cacheKey);
52 52
     $this->assertNotEmpty($data);
53 53
     $this->assertEquals($cacheData, $data);
54
-  }
54
+    }
55 55
 
56
-  public function testExpiredCacheInRedis()
57
-  {
56
+    public function testExpiredCacheInRedis()
57
+    {
58 58
     $cacheKey = 'expired_key';
59 59
     $cacheData = ['name' => 'Expired User', 'email' => '[email protected]'];
60 60
 
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
     $this->assertEquals("Cache stored successfully", $this->cache->getMessage());
65 65
     $this->assertEmpty($this->cache->getCache($cacheKey));
66 66
     $this->assertFalse($this->cache->isSuccess());
67
-  }
67
+    }
68 68
 
69
-  public function testOverwriteExistingCacheInRedis()
70
-  {
69
+    public function testOverwriteExistingCacheInRedis()
70
+    {
71 71
     $cacheKey = 'overwrite_key';
72 72
     $initialCacheData = ['name' => 'Initial Data', 'email' => '[email protected]'];
73 73
     $newCacheData = ['name' => 'New Data', 'email' => '[email protected]'];
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
     $this->cache->appendCache($cacheKey, $newCacheData);
79 79
     $this->assertEquals("Cache appended successfully", $this->cache->getMessage());
80 80
     $this->assertEquals($newCacheData, $this->cache->getCache($cacheKey));
81
-  }
81
+    }
82 82
 
83
-  public function testPutManyCacheItemsInRedis()
84
-  {
85
-     $items = [
83
+    public function testPutManyCacheItemsInRedis()
84
+    {
85
+        $items = [
86 86
             [
87 87
                 'cacheKey' => 'user_1_profile',
88 88
                 'cacheData' => [
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
     foreach ($items as $item) {
108 108
             $this->assertEquals($item['cacheData'], $this->cache->getCache($item['cacheKey']));
109 109
         }
110
-  }
110
+    }
111 111
 
112
-      public function testAppendCacheWithNamespaceInRedis()
112
+        public function testAppendCacheWithNamespaceInRedis()
113 113
     {
114 114
         $cacheKey = 'test_append_key_ns';
115 115
         $namespace = 'test_namespace';
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $this->assertEquals($expectedData, $cachedData);
133 133
     }
134 134
 
135
-      public function testDataOutputShouldBeOfTypeArray()
135
+        public function testDataOutputShouldBeOfTypeArray()
136 136
     {
137 137
 
138 138
         $this->cache->useFormatter();
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         $this->assertJson($cacheOutput);
179 179
     }
180 180
 
181
-      public function testClearCacheDataFromRedis()
181
+        public function testClearCacheDataFromRedis()
182 182
     {
183 183
         $cacheKey = 'test_key';
184 184
         $data = 'test_data';
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         $this->assertEmpty($this->cache->getCache($cacheKey));
194 194
     }
195 195
 
196
-  public function testFlushCacheDataFromRedis()
196
+    public function testFlushCacheDataFromRedis()
197 197
     {
198 198
         $key1 = 'test_key1';
199 199
         $data1 = 'test_data1';
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
         $this->assertEquals("Cache flushed successfully", $this->cache->getMessage());
213 213
     }
214 214
 
215
-  public function testHasCacheFromRedis()
216
-  {
215
+    public function testHasCacheFromRedis()
216
+    {
217 217
     $cacheKey = 'test_key';
218 218
     $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer'];
219 219
 
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 
222 222
     $this->assertEquals("Cache stored successfully", $this->cache->getMessage());
223 223
     $this->assertTrue($this->cache->isSuccess());
224
-  }
224
+    }
225 225
 
226
-  public function testRenewCacheFromRedis()
227
-  {
226
+    public function testRenewCacheFromRedis()
227
+    {
228 228
     $cacheKey = 'expired_key';
229 229
     $cacheData = ['name' => 'Expired User', 'email' => '[email protected]'];
230 230
 
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
     $this->cache->renewCache($cacheKey, 7200);
240 240
     $this->assertTrue($this->cache->isSuccess());
241 241
     $this->assertNotEmpty($this->cache->getCache($cacheKey));
242
-  }
242
+    }
243 243
 
244 244
     public function testRenewCacheWithNamespaceFromRedis()
245
-  {
245
+    {
246 246
     $cacheKey = 'expired_key';
247 247
     $namespace = 'expired_namespace';
248 248
     $cacheData = ['name' => 'Expired User', 'email' => '[email protected]'];
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
     $this->cache->renewCache($cacheKey, 7200, $namespace);
257 257
     $this->assertTrue($this->cache->isSuccess());
258 258
     $this->assertNotEmpty($this->cache->getCache($cacheKey, $namespace));
259
-  }
259
+    }
260 260
 
261
-  public function test_remember_saves_and_recover_values() 
261
+    public function test_remember_saves_and_recover_values() 
262 262
     {
263 263
         $this->cache->flushCache();
264 264
 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
     }
294 294
 
295 295
 
296
-      public function test_get_and_forget()
296
+        public function test_get_and_forget()
297 297
     {
298 298
         $cacheKey = 'cache_key_test';
299 299
         $this->cache->putCache($cacheKey, 10);
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         $this->assertNull($noCacheData);
315 315
     }
316 316
 
317
-      public function test_store_if_not_present_with_add_function()
317
+        public function test_store_if_not_present_with_add_function()
318 318
     {
319 319
         $existentKey = 'cache_key_test';
320 320
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 
339 339
     }
340 340
 
341
-      public function test_increment_function() {
341
+        public function test_increment_function() {
342 342
 
343 343
         $cacheKey = 'test_increment';
344 344
         $cacheData = 2025;
Please login to merge, or discard this patch.
tests/Unit/ArrayCacheStoreTest.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  discard block
 block discarded – undo
7 7
 class ArrayCacheStoreTest extends TestCase
8 8
 {
9 9
 
10
-  private $cache;
10
+    private $cache;
11 11
 
12
-  protected function setUp(): void
13
-  {
12
+    protected function setUp(): void
13
+    {
14 14
     $this->cache = new Cacheer();
15 15
     $this->cache->setDriver()->useArrayDriver();
16 16
     $this->cache->setConfig()->setTimeZone('America/Toronto');
17
-  }
17
+    }
18 18
 
19
-  protected function tearDown(): void
20
-  {
19
+    protected function tearDown(): void
20
+    {
21 21
     $this->cache->flushCache();
22
-  }
22
+    }
23 23
 
24 24
     public function testUsingArrayDriverSetsProperInstance()
25
-  {
25
+    {
26 26
     $this->assertInstanceOf(ArrayCacheStore::class, $this->cache->cacheStore);
27
-  }
27
+    }
28 28
 
29
-  public function testPutAndGetCacheInArray()
30
-  {
31
-      $cacheKey = 'test_key';
32
-      $cacheData = ['name' => 'John Doe', 'email' => '[email protected]'];
29
+    public function testPutAndGetCacheInArray()
30
+    {
31
+        $cacheKey = 'test_key';
32
+        $cacheData = ['name' => 'John Doe', 'email' => '[email protected]'];
33 33
       
34
-      $this->cache->putCache($cacheKey, $cacheData, '', 3600);
34
+        $this->cache->putCache($cacheKey, $cacheData, '', 3600);
35 35
 
36
-      $result = $this->cache->getCache($cacheKey);
36
+        $result = $this->cache->getCache($cacheKey);
37 37
 
38
-      $this->assertNotEmpty($result);
39
-      $this->assertEquals($cacheData, $result);
40
-  }
38
+        $this->assertNotEmpty($result);
39
+        $this->assertEquals($cacheData, $result);
40
+    }
41 41
 
42
-  public function testExpiredCacheInArray()
43
-  {
42
+    public function testExpiredCacheInArray()
43
+    {
44 44
     $cacheKey = 'expired_key';
45 45
     $cacheData = ['name' => 'Expired User', 'email' => '[email protected]'];
46 46
 
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
     $this->assertEquals("Cache stored successfully", $this->cache->getMessage());
51 51
     $this->assertEmpty($this->cache->getCache($cacheKey));
52 52
     $this->assertFalse($this->cache->isSuccess());
53
-  }
53
+    }
54 54
 
55 55
 
56
-  public function testOverwriteExistingCacheInArray()
57
-  {
56
+    public function testOverwriteExistingCacheInArray()
57
+    {
58 58
     $cacheKey = 'overwrite_key';
59 59
     $initialCacheData = ['name' => 'Initial Data', 'email' => '[email protected]'];
60 60
     $newCacheData = ['name' => 'New Data', 'email' => '[email protected]'];
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
     $this->cache->appendCache($cacheKey, $newCacheData);
66 66
     $this->assertEquals("Cache appended successfully", $this->cache->getMessage());
67 67
     $this->assertEquals($newCacheData, $this->cache->getCache($cacheKey));
68
-  }
68
+    }
69 69
 
70 70
 
71
-  public function testPutManyCacheItemsInArray()
72
-  {
73
-     $items = [
71
+    public function testPutManyCacheItemsInArray()
72
+    {
73
+        $items = [
74 74
             [
75 75
                 'cacheKey' => 'user_1_profile',
76 76
                 'cacheData' => [
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
           
97 97
             $this->assertEquals($item['cacheData'], $this->cache->getCache($item['cacheKey']));
98 98
         }
99
-  }
99
+    }
100 100
 
101
-  public function testHasCacheFromArray()
102
-  {
101
+    public function testHasCacheFromArray()
102
+    {
103 103
     $cacheKey = 'test_key';
104 104
     $cacheData = ['name' => 'Sílvio Silva', 'role' => 'Developer'];
105 105
 
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
 
111 111
     $this->cache->has($cacheKey);
112 112
     $this->assertTrue($this->cache->isSuccess());
113
-  }
113
+    }
114 114
 
115 115
     public function testRenewCacheFromArray()
116
-  {
116
+    {
117 117
     $cacheKey = 'expired_key';
118 118
     $cacheData = ['name' => 'Expired User', 'email' => '[email protected]'];
119 119
 
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
     $this->cache->renewCache($cacheKey, 7200);
129 129
     $this->assertTrue($this->cache->isSuccess());
130 130
     $this->assertNotEmpty($this->cache->getCache($cacheKey));
131
-  }
131
+    }
132 132
 
133
-      public function testRenewCacheWithNamespaceFromArray()
134
-  {
133
+        public function testRenewCacheWithNamespaceFromArray()
134
+    {
135 135
     $cacheKey = 'expired_key';
136 136
     $namespace = 'expired_namespace';
137 137
     $cacheData = ['name' => 'Expired User', 'email' => '[email protected]'];
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     $this->cache->renewCache($cacheKey, 7200, $namespace);
146 146
     $this->assertTrue($this->cache->isSuccess());
147 147
     $this->assertNotEmpty($this->cache->getCache($cacheKey, $namespace));
148
-  }
148
+    }
149 149
 
150 150
     public function testClearCacheDataFromArray()
151 151
     {
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         $this->assertEquals("Cache flushed successfully", $this->cache->getMessage());
182 182
     }
183 183
 
184
-  public function test_remember_saves_and_recover_values() 
184
+    public function test_remember_saves_and_recover_values() 
185 185
     {
186 186
         $this->cache->flushCache();
187 187
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     }
217 217
 
218 218
 
219
-      public function test_get_and_forget()
219
+        public function test_get_and_forget()
220 220
     {
221 221
         $cacheKey = 'cache_key_test';
222 222
         $this->cache->putCache($cacheKey, 10);
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         $this->assertNull($noCacheData);
238 238
     }
239 239
 
240
-      public function test_store_if_not_present_with_add_function()
240
+        public function test_store_if_not_present_with_add_function()
241 241
     {
242 242
         $existentKey = 'cache_key_test';
243 243
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 
262 262
     }
263 263
 
264
-      public function test_increment_function() {
264
+        public function test_increment_function() {
265 265
 
266 266
         $cacheKey = 'test_increment';
267 267
         $cacheData = 2025;
Please login to merge, or discard this patch.
src/Helpers/CacheFileHelper.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 {
14 14
 
15 15
     /**
16
-    * @param string $expiration
17
-    * @return int
18
-    */
16
+     * @param string $expiration
17
+     * @return int
18
+     */
19 19
     public static function convertExpirationToSeconds(string $expiration)
20 20
     {
21 21
         $units = [
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
     }
64 64
 
65 65
     /**
66
-    * @param string|int $ttl
67
-    * @param int $defaultTTL
68
-    * @return mixed
69
-    */
66
+     * @param string|int $ttl
67
+     * @param int $defaultTTL
68
+     * @return mixed
69
+     */
70 70
     public static function ttl($ttl = null, ?int $defaultTTL = null) {
71 71
         if ($ttl) {
72 72
             $ttl = is_string($ttl) ? CacheFileHelper::convertExpirationToSeconds($ttl) : $ttl;
@@ -76,19 +76,19 @@  discard block
 block discarded – undo
76 76
         return $ttl;
77 77
     }
78 78
 
79
-  /**
80
-  * @param mixed $currentCacheData
81
-  * @param mixed $cacheData
82
-  * @return array
83
-  */
84
-  public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData)
85
-  {
79
+    /**
80
+     * @param mixed $currentCacheData
81
+     * @param mixed $cacheData
82
+     * @return array
83
+     */
84
+    public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData)
85
+    {
86 86
     if (is_array($currentCacheData) && is_array($cacheData)) {
87
-      $mergedCacheData = array_merge($currentCacheData, $cacheData);
87
+        $mergedCacheData = array_merge($currentCacheData, $cacheData);
88 88
     } else {
89
-      $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData);
89
+        $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData);
90 90
     }
91 91
 
92 92
     return $mergedCacheData;
93
-  }
93
+    }
94 94
 }
Please login to merge, or discard this patch.
src/Core/ConnectionFactory.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
     /**
18
-      * @param array|null $database
19
-      * @return PDO|null
20
-    */
18
+     * @param array|null $database
19
+     * @return PDO|null
20
+     */
21 21
     public static function createConnection(?array $database = null)
22 22
     {
23 23
         $dbConf = $database ?? CACHEER_DATABASE_CONFIG[Connect::getConnection()];
Please login to merge, or discard this patch.
src/Core/Connect.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 
19 19
 
20 20
     /**
21
-    * @param array|null $database
22
-    * @return PDO|null
23
-    */
21
+     * @param array|null $database
22
+     * @return PDO|null
23
+     */
24 24
     public static function getInstance(?array $database = null)
25 25
     {
26 26
         $pdo = ConnectionFactory::createConnection($database);
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
     }
32 32
 
33 33
     /**
34
-    * @param string $connection
35
-    * @return void
36
-    */
34
+     * @param string $connection
35
+     * @return void
36
+     */
37 37
     public static function setConnection(string $connection)
38 38
     {
39 39
         $drivers = ['mysql', 'sqlite', 'pgsql'];
@@ -44,16 +44,16 @@  discard block
 block discarded – undo
44 44
     }
45 45
 
46 46
     /**
47
-    * @return string
48
-    */
47
+     * @return string
48
+     */
49 49
     public static function getConnection()
50 50
     {
51 51
         return self::$connection;
52 52
     }
53 53
 
54 54
     /**
55
-    * @return PDOException|null
56
-    */
55
+     * @return PDOException|null
56
+     */
57 57
     public static function getError()
58 58
     {
59 59
         return self::$error;
Please login to merge, or discard this patch.
src/Config/Option/Builder/OptionBuilder.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@
 block discarded – undo
11 11
  */
12 12
 class OptionBuilder
13 13
 {
14
-  /**
15
-  * @return FileOptionBuilder
16
-  */
17
-  public static function forFile() 
18
-  {
14
+    /**
15
+     * @return FileOptionBuilder
16
+     */
17
+    public static function forFile() 
18
+    {
19 19
     return new FileOptionBuilder();
20
-  }
20
+    }
21 21
 }
Please login to merge, or discard this patch.
src/Utils/CacheDriver.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
     }
66 66
 
67 67
     /**
68
-    * @return Cacheer
69
-    */
68
+     * @return Cacheer
69
+     */
70 70
     public function useArrayDriver()
71 71
     {
72 72
         $this->cacheer->cacheStore = new ArrayCacheStore($this->logPath);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
     /**
77 77
      * @return Cacheer
78
-    */
78
+     */
79 79
     public function useDefaultDriver()
80 80
     {
81 81
         if (!isset($this->cacheer->options['cacheDir'])) {
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
     }
93 93
 
94 94
     /**
95
-    * @param mixed $dirName
96
-    * @return bool
97
-    */
95
+     * @param mixed $dirName
96
+     * @return bool
97
+     */
98 98
     private function isDir(mixed $dirName)
99 99
     {
100
-      if (is_dir($dirName)) {
101
-          return true;
102
-      }
103
-      return mkdir($dirName, 0755, true);
100
+        if (is_dir($dirName)) {
101
+            return true;
102
+        }
103
+        return mkdir($dirName, 0755, true);
104 104
     }
105 105
 }
Please login to merge, or discard this patch.
src/CacheStore/ArrayCacheStore.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -13,124 +13,124 @@  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
-  public function __construct(string $logPath)
37
-  {
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
+    public function __construct(string $logPath)
37
+    {
38 38
     $this->logger = new CacheLogger($logPath);
39
-  }
40
-
41
-  /**
42
-   * @param string $cacheKey
43
-   * @param mixed  $cacheData
44
-   * @param string $namespace
45
-   * @return bool
46
-   */
47
-  public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = '')
48
-  {
49
-      $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
50
-
51
-      if (!$this->has($cacheKey, $namespace)) {
52
-          $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false);
53
-          $this->logger->debug("{$this->getMessage()} from array driver.");
54
-          return false;
55
-      }
56
-
57
-      $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData);
58
-      $this->setMessage("Cache appended successfully", true);
59
-      return true;
60
-  }
61
-
62
-  /**
63
-   * @param string $cacheKey
64
-   * @param string $namespace
65
-   * @return string
66
-   */
67
-  private function buildArrayKey(string $cacheKey, string $namespace = '')
68
-  {
39
+    }
40
+
41
+    /**
42
+     * @param string $cacheKey
43
+     * @param mixed  $cacheData
44
+     * @param string $namespace
45
+     * @return bool
46
+     */
47
+    public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = '')
48
+    {
49
+        $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
50
+
51
+        if (!$this->has($cacheKey, $namespace)) {
52
+            $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false);
53
+            $this->logger->debug("{$this->getMessage()} from array driver.");
54
+            return false;
55
+        }
56
+
57
+        $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData);
58
+        $this->setMessage("Cache appended successfully", true);
59
+        return true;
60
+    }
61
+
62
+    /**
63
+     * @param string $cacheKey
64
+     * @param string $namespace
65
+     * @return string
66
+     */
67
+    private function buildArrayKey(string $cacheKey, string $namespace = '')
68
+    {
69 69
     return !empty($namespace) ? ($namespace . ':' . $cacheKey) : $cacheKey;
70
-  }
71
-
72
-  /**
73
-   * @param string $cacheKey
74
-   * @param string $namespace
75
-   * @return void
76
-   */
77
-  public function clearCache(string $cacheKey, string $namespace = '')
78
-  {
70
+    }
71
+
72
+    /**
73
+     * @param string $cacheKey
74
+     * @param string $namespace
75
+     * @return void
76
+     */
77
+    public function clearCache(string $cacheKey, string $namespace = '')
78
+    {
79 79
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
80 80
     unset($this->arrayStore[$arrayStoreKey]);
81 81
     $this->setMessage("Cache cleared successfully", true);
82 82
     $this->logger->debug("{$this->getMessage()} from array driver.");
83
-  }
84
-
85
-  /**
86
-   * @param string $cacheKey
87
-   * @param int $amount
88
-   * @param string $namespace
89
-   * @return bool
90
-   */
91
-  public function decrement(string $cacheKey, int $amount = 1, string $namespace = '')
92
-  {
83
+    }
84
+
85
+    /**
86
+     * @param string $cacheKey
87
+     * @param int $amount
88
+     * @param string $namespace
89
+     * @return bool
90
+     */
91
+    public function decrement(string $cacheKey, int $amount = 1, string $namespace = '')
92
+    {
93 93
     return $this->increment($cacheKey, ($amount * -1), $namespace);
94
-  }
94
+    }
95 95
 
96
-  /**
97
-   * @return void
98
-   */
99
-  public function flushCache()
100
-  {
96
+    /**
97
+     * @return void
98
+     */
99
+    public function flushCache()
100
+    {
101 101
     unset($this->arrayStore);
102 102
     $this->arrayStore = [];
103 103
     $this->setMessage("Cache flushed successfully", true);
104 104
     $this->logger->debug("{$this->getMessage()} from array driver.");
105
-  }
106
-
107
-  /**
108
-   * @param string $cacheKey
109
-   * @param mixed $cacheData
110
-   * @param string $namespace
111
-   * @param int|string $ttl
112
-   * @return void
113
-   */
114
-  public function forever(string $cacheKey, mixed $cacheData)
115
-  {
105
+    }
106
+
107
+    /**
108
+     * @param string $cacheKey
109
+     * @param mixed $cacheData
110
+     * @param string $namespace
111
+     * @param int|string $ttl
112
+     * @return void
113
+     */
114
+    public function forever(string $cacheKey, mixed $cacheData)
115
+    {
116 116
     $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000);
117 117
     $this->setMessage($this->getMessage(), $this->isSuccess());
118
-  }
119
-
120
-  /**
121
-   * @param string $cacheKey
122
-   * @param string $namespace
123
-   * @param int|string $ttl
124
-   * @return mixed
125
-   */
126
-  public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600)
127
-  {
118
+    }
119
+
120
+    /**
121
+     * @param string $cacheKey
122
+     * @param string $namespace
123
+     * @param int|string $ttl
124
+     * @return mixed
125
+     */
126
+    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600)
127
+    {
128 128
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
129 129
 
130 130
     if (!$this->has($cacheKey, $namespace)) {
131
-      $this->setMessage("cacheData not found, does not exists or expired", false);
132
-      $this->logger->debug("{$this->getMessage()} from array driver.");
133
-      return false;
131
+        $this->setMessage("cacheData not found, does not exists or expired", false);
132
+        $this->logger->debug("{$this->getMessage()} from array driver.");
133
+        return false;
134 134
     }
135 135
 
136 136
     $cacheData = $this->arrayStore[$arrayStoreKey];
@@ -138,112 +138,112 @@  discard block
 block discarded – undo
138 138
     $now = time();
139 139
 
140 140
     if($expirationTime !== 0 && $now >= $expirationTime) {
141
-      list($np, $key) = explode(':', $arrayStoreKey);
142
-      $this->clearCache($key, $np);
143
-      $this->setMessage("cacheKey: {$key} has expired.", false);
144
-      $this->logger->debug("{$this->getMessage()} from array driver.");
145
-      return false;
141
+        list($np, $key) = explode(':', $arrayStoreKey);
142
+        $this->clearCache($key, $np);
143
+        $this->setMessage("cacheKey: {$key} has expired.", false);
144
+        $this->logger->debug("{$this->getMessage()} from array driver.");
145
+        return false;
146 146
     }
147 147
 
148 148
     $this->setMessage("Cache retrieved successfully", true);
149 149
     $this->logger->debug("{$this->getMessage()} from array driver.");
150 150
     return $this->serialize($cacheData['cacheData'], false);
151
-  }
152
-
153
-  /**
154
-   * @param string $cacheKey
155
-   * @param string $namespace
156
-   * @return bool
157
-   */
158
-  public function has(string $cacheKey, string $namespace = '')
159
-  {
151
+    }
152
+
153
+    /**
154
+     * @param string $cacheKey
155
+     * @param string $namespace
156
+     * @return bool
157
+     */
158
+    public function has(string $cacheKey, string $namespace = '')
159
+    {
160 160
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
161 161
     return isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime'];
162
-  }
163
-
164
-  /**
165
-   * @param string $cacheKey
166
-   * @param int $amount
167
-   * @param string $namespace
168
-   * @return bool
169
-   */
170
-  public function increment(string $cacheKey, int $amount = 1, string $namespace = '')
171
-  {
162
+    }
163
+
164
+    /**
165
+     * @param string $cacheKey
166
+     * @param int $amount
167
+     * @param string $namespace
168
+     * @return bool
169
+     */
170
+    public function increment(string $cacheKey, int $amount = 1, string $namespace = '')
171
+    {
172 172
     $cacheData = $this->getCache($cacheKey, $namespace);
173 173
 
174 174
     if(!empty($cacheData) && is_numeric($cacheData)) {
175
-      $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
176
-      $this->setMessage($this->getMessage(), $this->isSuccess());
177
-      return true;
175
+        $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace);
176
+        $this->setMessage($this->getMessage(), $this->isSuccess());
177
+        return true;
178 178
     }
179 179
 
180 180
     return false;
181
-  }
181
+    }
182 182
 
183
-  /**
184
-   * @return boolean
185
-   */
186
-  public function isSuccess()
187
-  {
183
+    /**
184
+     * @return boolean
185
+     */
186
+    public function isSuccess()
187
+    {
188 188
     return $this->success;
189
-  }
189
+    }
190 190
 
191
-  /**
192
-   * @return string
193
-   */
194
-  public function getMessage()
195
-  {
191
+    /**
192
+     * @return string
193
+     */
194
+    public function getMessage()
195
+    {
196 196
     return $this->message;
197
-  }
198
-
199
-  /**
200
-   * @param string $cacheKey
201
-   * @param mixed $cacheData
202
-   * @param string $namespace
203
-   * @param int|string $ttl
204
-   * @return bool
205
-   */
206
-  public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
207
-  {
197
+    }
198
+
199
+    /**
200
+     * @param string $cacheKey
201
+     * @param mixed $cacheData
202
+     * @param string $namespace
203
+     * @param int|string $ttl
204
+     * @return bool
205
+     */
206
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600)
207
+    {
208 208
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
209 209
 
210 210
     $this->arrayStore[$arrayStoreKey] = [
211
-      'cacheData' => serialize($cacheData),
212
-      'expirationTime' => time() + $ttl
211
+        'cacheData' => serialize($cacheData),
212
+        'expirationTime' => time() + $ttl
213 213
     ];
214 214
 
215 215
     $this->setMessage("Cache stored successfully", true);
216 216
     $this->logger->debug("{$this->getMessage()} from Array driver.");
217 217
     return true;
218
-  }
219
-
220
-  /**
221
-   * @param array $items
222
-   * @param string $namespace
223
-   * @param int $batchSize
224
-   * @return void
225
-   */
226
-  public function putMany(array $items, string $namespace = '', int $batchSize = 100)
227
-  {
218
+    }
219
+
220
+    /**
221
+     * @param array $items
222
+     * @param string $namespace
223
+     * @param int $batchSize
224
+     * @return void
225
+     */
226
+    public function putMany(array $items, string $namespace = '', int $batchSize = 100)
227
+    {
228 228
     $chunks = array_chunk($items, $batchSize, true);
229 229
 
230 230
     foreach ($chunks as $chunk) {
231
-      foreach ($chunk as $key => $data) {
232
-          $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
231
+        foreach ($chunk as $key => $data) {
232
+            $this->putCache($data['cacheKey'], $data['cacheData'], $namespace);
233
+        }
233 234
         }
234
-      }
235 235
     $this->setMessage("{$this->getMessage()}", $this->isSuccess());
236 236
     $this->logger->debug("{$this->getMessage()} from Array driver.");
237
-  }
238
-
239
-  /**
240
-   * @param string $cacheKey
241
-   * @param string|int $ttl
242
-   * @param string $namespace
243
-   * @return void
244
-   */
245
-  public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '')
246
-  {
237
+    }
238
+
239
+    /**
240
+     * @param string $cacheKey
241
+     * @param string|int $ttl
242
+     * @param string $namespace
243
+     * @return void
244
+     */
245
+    public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '')
246
+    {
247 247
     $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace);
248 248
 
249 249
     if (isset($this->arrayStore[$arrayStoreKey])) {
@@ -251,27 +251,27 @@  discard block
 block discarded – undo
251 251
         $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds;
252 252
         $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true);
253 253
         $this->logger->debug("{$this->getMessage()} from array driver.");
254
-      }
255
-  }
256
-
257
-  /**
258
-   * @param string  $message
259
-   * @param boolean $success
260
-   * @return void
261
-   */
262
-  private function setMessage(string $message, bool $success)
263
-  {
254
+        }
255
+    }
256
+
257
+    /**
258
+     * @param string  $message
259
+     * @param boolean $success
260
+     * @return void
261
+     */
262
+    private function setMessage(string $message, bool $success)
263
+    {
264 264
     $this->message = $message;
265 265
     $this->success = $success;
266
-  }
267
-
268
-  /**
269
-   * @param mixed $data
270
-   * @param bool $serialize
271
-   * @return mixed
272
-   */
273
-  private function serialize(mixed $data, bool $serialize = true)
274
-  {
266
+    }
267
+
268
+    /**
269
+     * @param mixed $data
270
+     * @param bool $serialize
271
+     * @return mixed
272
+     */
273
+    private function serialize(mixed $data, bool $serialize = true)
274
+    {
275 275
     return $serialize ? serialize($data) : unserialize($data);
276
-  }
276
+    }
277 277
 }
Please login to merge, or discard this patch.