PoolDecorator   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 70
ccs 28
cts 28
cp 1
rs 10
c 1
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getItem() 0 4 1
A hasItem() 0 4 1
A clear() 0 4 1
A deleteItems() 0 4 1
A deleteItem() 0 4 1
A save() 0 4 1
A saveDeferred() 0 4 1
A commit() 0 4 1
decorate() 0 1 ?
A getItems() 0 6 1
A proxySave() 0 10 3
1
<?php
2
namespace Jsq\CacheEncryption;
3
4
use Psr\Cache\CacheItemInterface;
5
use Psr\Cache\CacheItemPoolInterface;
6
7
abstract class PoolDecorator implements CacheItemPoolInterface
8
{
9
    /** @var CacheItemPoolInterface */
10
    private $decorated;
11
12 1308
    public function __construct(CacheItemPoolInterface $decorated)
13
    {
14 1308
        $this->decorated = $decorated;
15 1308
    }
16
17 684
    public function getItem($key)
18
    {
19 684
        return $this->decorate($this->decorated->getItem($key));
20
    }
21
22 231
    public function hasItem($key)
23
    {
24 231
        return $this->getItem($key)->isHit();
25
    }
26
27
    public function getItems(array $keys = [])
28
    {
29 189
        return array_map(function (CacheItemInterface $inner) {
30 27
            return $this->decorate($inner);
31 189
        }, $this->decorated->getItems($keys));
32
    }
33
34 1299
    public function clear()
35
    {
36 1299
        return $this->decorated->clear();
37
    }
38
39 171
    public function deleteItems(array $keys)
40
    {
41 171
        return $this->decorated->deleteItems($keys);
42
    }
43
44 189
    public function deleteItem($key)
45
    {
46 189
        return $this->decorated->deleteItem($key);
47
    }
48
49 162
    public function save(CacheItemInterface $item)
50
    {
51 162
        return $this->proxySave($item);
52
    }
53
54 90
    public function saveDeferred(CacheItemInterface $item)
55
    {
56 90
        return $this->proxySave($item, true);
57
    }
58
59 252
    private function proxySave(CacheItemInterface $item, $deferred = false)
60
    {
61 252
        if ($item instanceof ItemDecorator) {
62 180
            return $this->decorated
63 180
                ->{$deferred ? 'saveDeferred' : 'save'}($item->getDecorated());
64
        }
65
66 72
        throw new InvalidArgumentException('The provided cache item cannot'
67 72
            . ' be saved, as it did not originate from this cache.');
68
    }
69
70 72
    public function commit()
71
    {
72 72
        return $this->decorated->commit();
73
    }
74
75
    abstract protected function decorate(CacheItemInterface $inner);
76
}
77