Completed
Push — master ( f21d3b...aa6feb )
by Martin
04:21
created

NullCacheItemPool   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 145
ccs 22
cts 22
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getItem() 0 4 1
A getItems() 0 10 2
A hasItem() 0 4 1
A clear() 0 4 1
A deleteItem() 0 4 1
A deleteItems() 0 4 1
A save() 0 4 1
A saveDeferred() 0 4 1
A commit() 0 4 1
1
<?php
2
namespace Psr6NullCache;
3
4
use Psr\Cache\CacheItemPoolInterface;
5
use Psr\Cache\CacheItemInterface;
6
7
final class NullCacheItemPool implements CacheItemPoolInterface
8
{
9
10
    /**
11
     * Returns a Cache Item representing the specified key.
12
     *
13
     * This method must always return a CacheItemInterface object, even in case of
14
     * a cache miss. It MUST NOT return null.
15
     *
16
     * @param string $key
17
     *            The key for which to return the corresponding Cache Item.
18
     *            
19
     * @throws InvalidArgumentException If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
20
     *         MUST be thrown.
21
     *        
22
     * @return CacheItemInterface
23
     */
24 2
    public function getItem($key)
25
    {
26 2
        return new CacheItem($key, null, false);
27
    }
28
29
    /**
30
     * Returns a traversable set of cache items.
31
     *
32
     * @param array $keys
33
     *            An indexed array of keys of items to retrieve.
34
     *            
35
     * @throws InvalidArgumentException If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
36
     *         MUST be thrown.
37
     *        
38
     * @return array|\Traversable A traversable collection of Cache Items keyed by the cache keys of
39
     *         each item. A Cache item will be returned for each key, even if that
40
     *         key is not found. However, if no keys are specified then an empty
41
     *         traversable MUST be returned instead.
42
     */
43 1
    public function getItems(array $keys = [])
44
    {
45 1
        $result = [];
46
        
47 1
        foreach ($keys as $key) {
48 1
            $result[$key] = $this->getItem($key);
49 1
        }
50
        
51 1
        return $result;
52
    }
53
54
    /**
55
     * Confirms if the cache contains specified cache item.
56
     *
57
     * Note: This method MAY avoid retrieving the cached value for performance reasons.
58
     * This could result in a race condition with CacheItemInterface::get(). To avoid
59
     * such situation use CacheItemInterface::isHit() instead.
60
     *
61
     * @param string $key
62
     *            The key for which to check existence.
63
     *            
64
     * @throws InvalidArgumentException If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
65
     *         MUST be thrown.
66
     *        
67
     * @return bool True if item exists in the cache, false otherwise.
68
     */
69 1
    public function hasItem($key)
70
    {
71 1
        return false;
72
    }
73
74
    /**
75
     * Deletes all items in the pool.
76
     *
77
     * @return bool True if the pool was successfully cleared. False if there was an error.
78
     */
79 1
    public function clear()
80
    {
81 1
        return true;
82
    }
83
84
    /**
85
     * Removes the item from the pool.
86
     *
87
     * @param string $key
88
     *            The key for which to delete
89
     *            
90
     * @throws InvalidArgumentException If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
91
     *         MUST be thrown.
92
     *        
93
     * @return bool True if the item was successfully removed. False if there was an error.
94
     */
95 1
    public function deleteItem($key)
96
    {
97 1
        return true;
98
    }
99
100
    /**
101
     * Removes multiple items from the pool.
102
     *
103
     * @param array $keys
104
     *            An array of keys that should be removed from the pool.
105
     *            
106
     * @throws InvalidArgumentException If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
107
     *         MUST be thrown.
108
     *        
109
     * @return bool True if the items were successfully removed. False if there was an error.
110
     */
111 1
    public function deleteItems(array $keys)
112
    {
113 1
        return true;
114
    }
115
116
    /**
117
     * Persists a cache item immediately.
118
     *
119
     * @param CacheItemInterface $item
120
     *            The cache item to save.
121
     *            
122
     * @return bool True if the item was successfully persisted. False if there was an error.
123
     */
124 1
    public function save(CacheItemInterface $item)
125
    {
126 1
        return true;
127
    }
128
129
    /**
130
     * Sets a cache item to be persisted later.
131
     *
132
     * @param CacheItemInterface $item
133
     *            The cache item to save.
134
     *            
135
     * @return bool False if the item could not be queued or if a commit was attempted and failed. True otherwise.
136
     */
137 1
    public function saveDeferred(CacheItemInterface $item)
138
    {
139 1
        return true;
140
    }
141
142
    /**
143
     * Persists any deferred cache items.
144
     *
145
     * @return bool True if all not-yet-saved items were successfully saved or there were none. False otherwise.
146
     */
147 1
    public function commit()
148
    {
149 1
        return true;
150
    }
151
}
152