BlackholeCacheItemPoolDecorator   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 51.61%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 99
ccs 16
cts 31
cp 0.5161
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getItem() 0 4 1
A getItems() 0 9 2
A hasItem() 0 4 1
A clear() 0 4 1
A deleteItem() 0 4 1
A deleteItems() 0 4 1
A save() 0 8 2
A saveDeferred() 0 8 2
A commit() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MovingImage\Bundle\VMProApiBundle\Decorator;
6
7
use Psr\Cache\CacheItemInterface;
8
use Psr\Cache\CacheItemPoolInterface;
9
10
/**
11
 * Decorator that wraps around any CacheItemPoolInterface implementation
12
 * and overrides the `isHit` method by always returning false.
13
 * Therefore, this is a CacheItemPool implementation useful for forcing cache to be refreshed.
14
 */
15
class BlackholeCacheItemPoolDecorator implements CacheItemPoolInterface
16
{
17
    /**
18
     * Decorated CacheItemPool implementation.
19
     *
20
     * @var CacheItemPoolInterface
21
     */
22
    private $cacheItemPool;
23
24
    public function __construct(CacheItemPoolInterface $cacheItemPool)
25 16
    {
26
        $this->cacheItemPool = $cacheItemPool;
27 16
    }
28 16
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getItem($key): CacheItemInterface
33 14
    {
34
        return new BlackholeCacheItemDecorator($this->cacheItemPool->getItem($key));
35 14
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getItems(array $keys = [])
41 2
    {
42
        $items = [];
43 2
        foreach ($this->cacheItemPool->getItems($keys) as $item) {
44 2
            $items[] = new BlackholeCacheItemDecorator($item);
45 2
        }
46 2
47
        return $items;
48 2
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function hasItem($key): bool
54
    {
55
        return $this->cacheItemPool->hasItem($key);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function clear(): bool
62
    {
63
        return $this->cacheItemPool->clear();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function deleteItem($key): bool
70
    {
71
        return $this->cacheItemPool->deleteItem($key);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function deleteItems(array $keys): bool
78
    {
79
        return $this->cacheItemPool->deleteItems($keys);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function save(CacheItemInterface $item): bool
86 8
    {
87
        if ($item instanceof BlackholeCacheItemDecorator) {
88 8
            $item = $item->getDecoratedItem();
89 8
        }
90 8
91
        return $this->cacheItemPool->save($item);
92 8
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function saveDeferred(CacheItemInterface $item): bool
98
    {
99
        if ($item instanceof BlackholeCacheItemDecorator) {
100
            $item = $item->getDecoratedItem();
101
        }
102
103
        return $this->cacheItemPool->saveDeferred($item);
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function commit(): bool
110
    {
111
        return $this->cacheItemPool->commit();
112
    }
113
}
114