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

ItemDecorator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 54
ccs 21
cts 21
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getKey() 0 4 1
A getDecorated() 0 4 1
A set() 0 7 1
A isHit() 0 5 2
A expiresAt() 0 6 1
A expiresAfter() 0 6 1
encrypt() 0 1 ?
isDecryptable() 0 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