Passed
Push — main ( 72c6fa...9344f0 )
by Sílvio
02:59
created
tests/RedisTest.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -7,27 +7,27 @@  discard block
 block discarded – undo
7 7
 class RedisTest 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 testFlushCacheDataFromDatabase()
196
+    public function testFlushCacheDataFromDatabase()
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,6 +256,6 @@  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 261
 }
Please login to merge, or discard this patch.
src/Interface/CacheerInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@
 block discarded – undo
9 9
  */
10 10
 interface CacheerInterface
11 11
 {
12
-    public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600);
13
-    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600);
12
+    public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600);
13
+    public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600);
14 14
     public function flushCache();
15 15
     public function clearCache(string $cacheKey, string $namespace = '');
16 16
     public function has(string $cacheKey, string $namespace = '');
Please login to merge, or discard this patch.
src/Utils/CacheDataFormatter.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@  discard block
 block discarded – undo
18 18
     }
19 19
 
20 20
     /**
21
-    * @return string|false
22
-    */
21
+     * @return string|false
22
+     */
23 23
     public function toJson()
24 24
     {
25 25
         return json_encode(
@@ -31,24 +31,24 @@  discard block
 block discarded – undo
31 31
     }
32 32
 
33 33
     /**
34
-    * @return array
35
-    */
34
+     * @return array
35
+     */
36 36
     public function toArray()
37 37
     {
38 38
         return (array)$this->data;
39 39
     }
40 40
 
41 41
     /**
42
-    * @return string
43
-    */
42
+     * @return string
43
+     */
44 44
     public function toString()
45 45
     {
46 46
         return (string)$this->data;
47 47
     }
48 48
 
49 49
     /**
50
-    * @return object
51
-    */
50
+     * @return object
51
+     */
52 52
     public function toObject()
53 53
     {
54 54
         return (object)$this->data;
Please login to merge, or discard this patch.
src/Utils/CacheDriver.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -82,14 +82,14 @@
 block discarded – undo
82 82
     }
83 83
 
84 84
     /**
85
-    * @param mixed $dirName
86
-    * @return bool
87
-    */
85
+     * @param mixed $dirName
86
+     * @return bool
87
+     */
88 88
     private function isDir(mixed $dirName)
89 89
     {
90
-      if (is_dir($dirName)) {
91
-          return true;
92
-      }
93
-      return mkdir($dirName, 0755, true);
90
+        if (is_dir($dirName)) {
91
+            return true;
92
+        }
93
+        return mkdir($dirName, 0755, true);
94 94
     }
95 95
 }
Please login to merge, or discard this patch.
src/Utils/CacheLogger.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,49 +23,49 @@  discard block
 block discarded – undo
23 23
     }
24 24
 
25 25
     /**
26
-    * @return void
27
-    */
26
+     * @return void
27
+     */
28 28
     public function info($message)
29 29
     {
30 30
         $this->log('INFO', $message);
31 31
     }
32 32
 
33 33
     /**
34
-    * @return void
35
-    */
34
+     * @return void
35
+     */
36 36
     public function warning($message)
37 37
     {
38 38
         $this->log('WARNING', $message);
39 39
     }
40 40
 
41 41
     /**
42
-    * @return void
43
-    */
42
+     * @return void
43
+     */
44 44
     public function error($message)
45 45
     {
46 46
         $this->log('ERROR', $message);
47 47
     }
48 48
 
49 49
     /**
50
-    * @return void
51
-    */
50
+     * @return void
51
+     */
52 52
     public function debug($message)
53 53
     {
54 54
         $this->log('DEBUG', $message);
55 55
     }
56 56
 
57 57
     /**
58
-    * @param mixed $level
59
-    * @return string|int|false
60
-    */
58
+     * @param mixed $level
59
+     * @return string|int|false
60
+     */
61 61
     private function shouldLog(mixed $level)
62 62
     {
63 63
         return array_search($level, $this->logLevels) >= array_search($this->logLevel, $this->logLevels);
64 64
     }
65 65
 
66 66
     /**
67
-    * @return void
68
-    */
67
+     * @return void
68
+     */
69 69
     private function rotateLog()
70 70
     {
71 71
         if (file_exists($this->logFile) && filesize($this->logFile) >= $this->maxFileSize) {
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
     }
76 76
 
77 77
     /**
78
-    * @param mixed $level
79
-    * @param string $message
80
-    * @return void
81
-    */
78
+     * @param mixed $level
79
+     * @param string $message
80
+     * @return void
81
+     */
82 82
     private function log($level, $message)
83 83
     {
84 84
         if (!$this->shouldLog($level)) {
Please login to merge, or discard this patch.
src/Helpers/CacheRedisHelper.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@  discard block
 block discarded – undo
12 12
 class CacheRedisHelper
13 13
 {
14 14
 
15
-  /**
16
-  * @param mixed $data
17
-  * @param bool  $serialize
18
-  * @return string
19
-  */
20
-  public static function serialize(mixed $data, bool $serialize = true)
21
-  {
15
+    /**
16
+     * @param mixed $data
17
+     * @param bool  $serialize
18
+     * @return string
19
+     */
20
+    public static function serialize(mixed $data, bool $serialize = true)
21
+    {
22 22
     if($serialize) {
23
-      return serialize($data);
23
+        return serialize($data);
24 24
     }
25 25
 
26 26
     return unserialize($data);
27 27
 
28
-  }
28
+    }
29 29
 
30 30
     /**
31 31
      * @param array $item
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
         return (array)$cacheData;
55 55
     }
56 56
 
57
-  /**
58
-  * @param mixed $currentCacheData
59
-  * @param mixed $cacheData
60
-  * @return array
61
-  */
62
-  public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData)
63
-  {
57
+    /**
58
+     * @param mixed $currentCacheData
59
+     * @param mixed $cacheData
60
+     * @return array
61
+     */
62
+    public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData)
63
+    {
64 64
     if (is_array($currentCacheData) && is_array($cacheData)) {
65
-      $mergedCacheData = array_merge($currentCacheData, $cacheData);
65
+        $mergedCacheData = array_merge($currentCacheData, $cacheData);
66 66
     } else {
67
-      $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData);
67
+        $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData);
68 68
     }
69 69
 
70 70
     return $mergedCacheData;
71
-  }
71
+    }
72 72
 
73 73
 }
74 74
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
   */
20 20
   public static function serialize(mixed $data, bool $serialize = true)
21 21
   {
22
-    if($serialize) {
22
+    if ($serialize) {
23 23
       return serialize($data);
24 24
     }
25 25
 
Please login to merge, or discard this patch.
src/Helpers/CacheFileHelper.php 2 patches
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(string|int $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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
     * @param int $defaultTTL
68 68
     * @return mixed
69 69
     */
70
-    public static function ttl(string|int $ttl = null, int $defaultTTL = null) {
70
+    public static function ttl(string | int $ttl = null, int $defaultTTL = null) {
71 71
         if ($ttl) {
72 72
             $ttl = is_string($ttl) ? CacheFileHelper::convertExpirationToSeconds($ttl) : $ttl;
73 73
         } else {
Please login to merge, or discard this patch.
src/Helpers/CacheDatabaseHelper.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
         }
25 25
     }
26 26
 
27
-      /**
28
-     * @param array $options
29
-     * @return array
30
-     */
27
+        /**
28
+         * @param array $options
29
+         * @return array
30
+         */
31 31
     public static function mergeCacheData($cacheData)
32 32
     {
33 33
         if (is_array($cacheData) && is_array(reset($cacheData))) {
@@ -40,21 +40,21 @@  discard block
 block discarded – undo
40 40
         return (array)$cacheData;
41 41
     }
42 42
 
43
-  /**
44
-  * @param mixed $currentCacheData
45
-  * @param mixed $cacheData
46
-  * @return array
47
-  */
48
-  public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData)
49
-  {
43
+    /**
44
+     * @param mixed $currentCacheData
45
+     * @param mixed $cacheData
46
+     * @return array
47
+     */
48
+    public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData)
49
+    {
50 50
     if (is_array($currentCacheData) && is_array($cacheData)) {
51
-      $mergedCacheData = array_merge($currentCacheData, $cacheData);
51
+        $mergedCacheData = array_merge($currentCacheData, $cacheData);
52 52
     } else {
53
-      $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData);
53
+        $mergedCacheData = array_merge((array)$currentCacheData, (array)$cacheData);
54 54
     }
55 55
 
56 56
     return $mergedCacheData;
57
-  }
57
+    }
58 58
 
59 59
 }
60 60
 
Please login to merge, or discard this patch.
src/CacheStore/CacheManager/RedisCacheManager.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -8,38 +8,38 @@
 block discarded – undo
8 8
 class RedisCacheManager 
9 9
 {
10 10
 
11
-  /** @var Predis\Client */
12
-  private static $redis;
11
+    /** @var Predis\Client */
12
+    private static $redis;
13 13
 
14
-  /** @param string $namespace */
15
-  private static $namespace;
14
+    /** @param string $namespace */
15
+    private static $namespace;
16 16
 
17
-  /**
18
-  * @return Client
19
-  */
20
-  public static function connect()
21
-  {
17
+    /**
18
+     * @return Client
19
+     */
20
+    public static function connect()
21
+    {
22 22
     Autoloader::register();
23 23
     self::$redis = new Client([
24
-      'scheme' => 'tcp',
25
-      'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'],
26
-      'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'],
27
-      'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'],
28
-      'database' => 0
24
+        'scheme' => 'tcp',
25
+        'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'],
26
+        'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'],
27
+        'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'],
28
+        'database' => 0
29 29
     ]);
30 30
     self::auth();
31 31
     self::$namespace = REDIS_CONNECTION_CONFIG['REDIS_NAMESPACE'] ?? 'Cache';
32 32
     return self::$redis;
33
-  }
33
+    }
34 34
 
35
-  /**
36
-  * @return void
37
-  */
38
-  private static function auth()
39
-  {
35
+    /**
36
+     * @return void
37
+     */
38
+    private static function auth()
39
+    {
40 40
     if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
41
-      self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
41
+        self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
42
+    }
42 43
     }
43
-  }
44 44
 
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
   */
38 38
   private static function auth()
39 39
   {
40
-    if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
40
+    if (is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
41 41
       self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
42 42
     }
43 43
   }
Please login to merge, or discard this patch.