Completed
Push — master ( 789220...9af5c5 )
by Jonathan
04:43
created

EnvelopeEncryptedValue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 54
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A jsonSerialize() 0 7 1
A unserialize() 0 8 1
A getEnvelopeKey() 0 4 1
A getSignature() 0 4 1
1
<?php
2
namespace Jsq\Cache;
3
4
class EnvelopeEncryptedValue extends EncryptedValue
5
{
6
    /** @var string */
7
    private $envelopeKey;
8
    /** @var string */
9
    private $signature;
10
11
    /**
12
     * @param string $cipherText
13
     * @param string $method
14
     * @param string $iv
15
     * @param string $key
16
     * @param string $signature
17
     */
18 114
    public function __construct($cipherText, $method, $iv, $key, $signature)
19
    {
20 114
        parent::__construct($cipherText, $method, $iv);
21 114
        $this->envelopeKey = $key;
22 114
        $this->signature = $signature;
23 114
    }
24
25 3
    public function jsonSerialize()
26
    {
27 3
        return parent::jsonSerialize() + [
28 3
            'key' => base64_encode($this->envelopeKey),
29 3
            'signature' => base64_encode($this->signature),
30 3
        ];
31
    }
32
33 3
    public function unserialize($serialized)
34
    {
35 3
        parent::unserialize($serialized);
36
37 3
        $data = json_decode($serialized);
38 3
        $this->envelopeKey = base64_decode($data->key);
39 3
        $this->signature = base64_decode($data->signature);
40 3
    }
41
42
    /**
43
     * @return string
44
     */
45 66
    public function getEnvelopeKey()
46
    {
47 66
        return $this->envelopeKey;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 93
    public function getSignature()
54
    {
55 93
        return $this->signature;
56
    }
57
}
58