tokenPack   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 44
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A pack() 0 8 2
A unpack() 0 8 2
1
<?php
2
/**
3
 * ==================================
4
 * Responsible PHP API
5
 * ==================================
6
 *
7
 * @link Git https://github.com/vince-scarpa/responsibleAPI.git
8
 *
9
 * @api Responible API
10
 * @package responsible\core\throttle
11
 *
12
 * @author Vince scarpa <[email protected]>
13
 *
14
 */
15
namespace responsible\core\throttle;
16
17
use responsible\core\throttle;
18
use responsible\core\encoder;
19
20
class tokenPack
21
{
22
    /**
23
     * [$cipher]
24
     * @var object
25
     */
26
    private $cipher;
27
28
    /**
29
     * [__construct Call cipher class]
30
     */
31
    public function __construct()
32
    {
33
        $this->cipher = new encoder\cipher;
34
    }
35
36
    /**
37
     * [pack Tokenize the data array]
38
     * @return string
39
     */
40
    public function pack(array $data = array())
41
    {
42
        if (empty($data)) {
43
            return '';
44
        }
45
        return $this->cipher->encode(
46
            $this->cipher->jsonEncode(
47
                $data
48
            )
49
        );
50
    }
51
52
    /**
53
     * [pack Tokenize the data array]
54
     * @return array
55
     */
56
    public function unpack($data)
57
    {
58
        if (empty($data)) {
59
            return [];
60
        }
61
        return $this->cipher->jsonDecode(
62
            $this->cipher->decode(
63
                $data
64
            )
65
        );
66
    }
67
}
68