Util   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 81
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataWithExpire() 0 8 1
A hasInternalExpireTime() 0 9 4
A checkInteger() 0 6 3
A checkArgString() 0 6 2
A checkArgInteger() 0 6 2
A checkArgSerializable() 0 6 2
1
<?php namespace AdammBalogh\KeyValueStore\Adapter;
2
3
class Util
4
{
5
    /**
6
     * @param string $value
7
     * @param int $seconds
8
     * @param int $timestamp
9
     *
10
     * @return string
11
     */
12
    public static function getDataWithExpire($value, $seconds, $timestamp)
13
    {
14
        return serialize([
15
            'v' => $value,
16
            's' => $seconds,
17
            'ts' => $timestamp
18
        ]);
19
    }
20
21
    /**
22
     * @param mixed $unserializedValue
23
     *
24
     * @return bool
25
     */
26
    public static function hasInternalExpireTime($unserializedValue)
27
    {
28
        return (
29
            is_array($unserializedValue)
30
            && array_key_exists('v', $unserializedValue)
31
            && array_key_exists('s', $unserializedValue)
32
            && array_key_exists('ts', $unserializedValue)
33
        );
34
    }
35
36
    /**
37
     * @param string $param
38
     *
39
     * @throws \Exception
40
     */
41
    public static function checkInteger($param)
42
    {
43
        if (!is_numeric($param) || !is_integer($param + 0)) {
44
            throw new \Exception('The stored value is not an integer');
45
        }
46
    }
47
48
    /**
49
     * @param mixed $argument
50
     *
51
     * @throws \InvalidArgumentException
52
     */
53
    public static function checkArgString($argument)
54
    {
55
        if (!is_string($argument)) {
56
            throw new \InvalidArgumentException();
57
        }
58
    }
59
60
    /**
61
     * @param mixed $argument
62
     *
63
     * @throws \InvalidArgumentException
64
     */
65
    public static function checkArgInteger($argument)
66
    {
67
        if (!is_integer($argument)) {
68
            throw new \InvalidArgumentException();
69
        }
70
    }
71
72
    /**
73
     * @param mixed $argument
74
     *
75
     * @throws \InvalidArgumentException
76
     */
77
    public static function checkArgSerializable($argument)
78
    {
79
        if (is_resource($argument)) {
80
            throw new \InvalidArgumentException();
81
        }
82
    }
83
}
84