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

ItemDecorator::isHit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 2
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