PoolDecorator::decorate()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 1
b 0
f 0
nc 1
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