EncryptedValue   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 53
ccs 22
cts 22
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A jsonSerialize() 0 8 1
A serialize() 0 4 1
A unserialize() 0 7 1
A getCipherText() 0 4 1
A getMethod() 0 4 1
A getInitializationVector() 0 4 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