Completed
Push — master ( 7aadd0...e03480 )
by Jonathan
10s
created

ItemDecorator::getCipherMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Jsq\CacheEncryption;
3
4
use Psr\Cache\CacheItemInterface;
5
6
abstract class ItemDecorator implements CacheItemInterface
7
{
8
    /** @var CacheItemInterface */
9
    private $decorated;
10
    /** @var mixed */
11
    private $decrypted;
12
13 480
    public function __construct(CacheItemInterface $decorated)
14
    {
15 480
        $this->decorated = $decorated;
16 480
    }
17
18 231
    public function getKey()
19
    {
20 231
        return $this->decorated->getKey();
21
    }
22
23 426
    public function getDecorated()
24
    {
25 426
        return $this->decorated;
26
    }
27
28 324
    public function set($value)
29
    {
30 324
        $this->decorated->set($this->encrypt($value));
31 324
        $this->decrypted = $value;
32
33 324
        return $this;
34
    }
35
36 354
    public function isHit()
37
    {
38 354
        return $this->decorated->isHit()
39 354
            && $this->isDecryptable();
40
    }
41
42 102
    public function expiresAt($expiresAt)
43
    {
44 9
        $this->decorated->expiresAt($expiresAt);
45
46 9
        return $this;
47 102
    }
48
49 18
    public function expiresAfter($expiresAfter)
50
    {
51 18
        $this->decorated->expiresAfter($expiresAfter);
52
53 18
        return $this;
54
    }
55
56
    abstract protected function encrypt($data);
57
58
    abstract protected function isDecryptable();
59
}
60