CacheRedisHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
dl 0
loc 55
rs 10
c 2
b 0
f 1
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 7 2
A arrayIdentifier() 0 3 1
A mergeCacheData() 0 3 1
A validateCacheItem() 0 5 1
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\Helpers;
4
5
use Silviooosilva\CacheerPhp\Helpers\CacheerHelper;
6
use Silviooosilva\CacheerPhp\Exceptions\CacheRedisException;
7
8
/**
9
 * Class CacheRedisHelper
10
 * @author Sílvio Silva <https://github.com/silviooosilva>
11
 * @package Silviooosilva\CacheerPhp
12
 */
13
class CacheRedisHelper
14
{
15
16
  /**
17
  * serializes or unserializes data based on the $serialize flag.
18
  * 
19
  * @param mixed $data
20
  * @param bool  $serialize
21
  * @return mixed
22
  */
23
  public static function serialize(mixed $data, bool $serialize = true): mixed
24
  {
25
    if($serialize) {
26
      return serialize($data);
27
    }
28
29
    return unserialize($data);
30
31
  }
32
33
    /**
34
    * Validates a cache item.
35
    *  
36
    * @param array $item
37
    * @return void
38
    */
39
    public static function validateCacheItem(array $item): void
40
    {
41
        CacheerHelper::validateCacheItem(
42
            $item,
43
            fn($msg) => CacheRedisException::create($msg)
44
        );
45
    }
46
47
    /**
48
     * Merges cache data with existing data.
49
     *
50
     * @param $cacheData
51
     * @return array
52
     */
53
    public static function mergeCacheData($cacheData): array
54
    {
55
        return CacheerHelper::mergeCacheData($cacheData);
56
    }
57
58
  /**
59
  * Generates an array identifier for cache data.
60
  * 
61
  * @param mixed $currentCacheData
62
  * @param mixed $cacheData
63
  * @return array
64
  */
65
  public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData): array
66
  {
67
      return CacheerHelper::arrayIdentifier($currentCacheData, $cacheData);
68
  }
69
70
}
71
72