EncryptedValue::unserialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
namespace Jsq\Cache;
3
4
use JsonSerializable;
5
use Serializable;
6
7
abstract class EncryptedValue implements JsonSerializable, Serializable
8
{
9
    /** @var string */
10
    private $cipherText;
11
    /** @var string */
12
    private $method;
13
    /** @var string */
14
    private $initializationVector;
15
16 72
    public function __construct($cipherText, $method, $iv)
17
    {
18 72
        $this->cipherText = $cipherText;
19 72
        $this->method = $method;
20 72
        $this->initializationVector = $iv;
21 72
    }
22
23 36
    public function jsonSerialize()
24
    {
25
        return [
26 36
            'cipherText' => $this->cipherText,
27 36
            'method' => $this->method,
28 36
            'iv' => base64_encode($this->initializationVector),
29 36
        ];
30
    }
31
32 36
    public function serialize()
33
    {
34 36
        return json_encode($this->jsonSerialize());
35
    }
36
37 36
    public function unserialize($serialized)
38
    {
39 36
        $data = json_decode($serialized);
40 36
        $this->cipherText = $data->cipherText;
41 36
        $this->method = $data->method;
42 36
        $this->initializationVector = base64_decode($data->iv);
43 36
    }
44
45
    public function getCipherText(): string
46
    {
47
        return $this->cipherText;
48 72
    }
49
50 72
    public function getMethod(): string
51
    {
52
        return $this->method;
53
    }
54
55
    public function getInitializationVector(): string
56 36
    {
57
        return $this->initializationVector;
58 36
    }
59
}
60