1 | <?php |
||||
2 | /** |
||||
3 | * This file is part of the O2System Framework package. |
||||
4 | * |
||||
5 | * For the full copyright and license information, please view the LICENSE |
||||
6 | * file that was distributed with this source code. |
||||
7 | * |
||||
8 | * @author Steeve Andrian Salim |
||||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||
10 | */ |
||||
11 | |||||
12 | // ------------------------------------------------------------------------ |
||||
13 | |||||
14 | namespace O2System\Cache\Adapters\Memcached; |
||||
15 | |||||
16 | // ------------------------------------------------------------------------ |
||||
17 | |||||
18 | use O2System\Cache\Item; |
||||
19 | use Psr\Cache\CacheItemInterface; |
||||
0 ignored issues
–
show
|
|||||
20 | use Psr\Cache\CacheItemPoolInterface; |
||||
0 ignored issues
–
show
The type
Psr\Cache\CacheItemPoolInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
21 | use O2System\Spl\Exceptions\Logic\InvalidArgumentException; |
||||
22 | |||||
23 | /** |
||||
24 | * Class ItemPool |
||||
25 | * |
||||
26 | * @package O2System\Cache\Adapters\File |
||||
27 | */ |
||||
28 | class ItemPool extends Adapter implements CacheItemPoolInterface |
||||
29 | { |
||||
30 | /** |
||||
31 | * ItemPool::getItems |
||||
32 | * |
||||
33 | * Returns a traversable set of cache items. |
||||
34 | * |
||||
35 | * @param string[] $keys |
||||
36 | * An indexed array of keys of items to retrieve. |
||||
37 | * |
||||
38 | * @throws InvalidArgumentException |
||||
39 | * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
||||
40 | * MUST be thrown. |
||||
41 | * |
||||
42 | * @return array|\Traversable |
||||
43 | * A traversable collection of Cache Items keyed by the cache keys of |
||||
44 | * each item. A Cache item will be returned for each key, even if that |
||||
45 | * key is not found. However, if no keys are specified then an empty |
||||
46 | * traversable MUST be returned instead. |
||||
47 | */ |
||||
48 | public function getItems(array $keys = []) |
||||
49 | { |
||||
50 | if ( ! is_array($keys)) { |
||||
0 ignored issues
–
show
|
|||||
51 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_ARRAY_CACHE_EXCEPTION'); |
||||
52 | } |
||||
53 | |||||
54 | $items = []; |
||||
55 | |||||
56 | if (empty($keys)) { |
||||
57 | $allItems = $this->memcached->getAllKeys(); |
||||
58 | |||||
59 | foreach ($allItems as $server => $metadata) { |
||||
60 | foreach ($metadata[ 'items' ] AS $itemKey => $itemMetadata) { |
||||
61 | $cacheDump = $this->memcached->getExtendedStats('cachedump', (int)$itemKey); |
||||
0 ignored issues
–
show
The method
getExtendedStats() does not exist on Memcached .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
62 | |||||
63 | foreach ($cacheDump[ $server ] AS $cacheDumpItemKey => $cacheDumpItemMetadata) { |
||||
64 | $items[] = $this->getItem(str_replace($this->prefixKey, '', $cacheDumpItemKey)); |
||||
65 | } |
||||
66 | } |
||||
67 | } |
||||
68 | } elseif (count($keys)) { |
||||
69 | foreach ($keys as $key) { |
||||
70 | $items[] = $this->getItem($key); |
||||
71 | } |
||||
72 | } |
||||
73 | |||||
74 | return $items; |
||||
75 | } |
||||
76 | |||||
77 | // ------------------------------------------------------------------------ |
||||
78 | |||||
79 | /** |
||||
80 | * ItemPool::getKey |
||||
81 | * |
||||
82 | * Returns a Cache Item representing the specified key. |
||||
83 | * |
||||
84 | * This method must always return a CacheItemInterface object, even in case of |
||||
85 | * a cache miss. It MUST NOT return null. |
||||
86 | * |
||||
87 | * @param string $key |
||||
88 | * The key for which to return the corresponding Cache Item. |
||||
89 | * |
||||
90 | * @throws InvalidArgumentException |
||||
91 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||||
92 | * MUST be thrown. |
||||
93 | * |
||||
94 | * @return CacheItemInterface |
||||
95 | * The corresponding Cache Item. |
||||
96 | */ |
||||
97 | public function getItem($key) |
||||
98 | { |
||||
99 | if ( ! is_string($key)) { |
||||
0 ignored issues
–
show
|
|||||
100 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION'); |
||||
101 | } |
||||
102 | |||||
103 | $metadata = $this->memcached->get($this->prefixKey . $key); |
||||
104 | $metadata = isset($metadata[ 0 ]) ? $metadata[ 0 ] : $metadata; |
||||
105 | |||||
106 | return new Item($key, $metadata); |
||||
107 | } |
||||
108 | |||||
109 | // ------------------------------------------------------------------------ |
||||
110 | |||||
111 | /** |
||||
112 | * ItemPool::hasItem |
||||
113 | * |
||||
114 | * Confirms if the cache contains specified cache item. |
||||
115 | * |
||||
116 | * Note: This method MAY avoid retrieving the cached value for performance reasons. |
||||
117 | * This could result in a race condition with CacheItemInterface::get(). To avoid |
||||
118 | * such situation use CacheItemInterface::isHit() instead. |
||||
119 | * |
||||
120 | * @param string $key |
||||
121 | * The key for which to check existence. |
||||
122 | * |
||||
123 | * @throws InvalidArgumentException |
||||
124 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||||
125 | * MUST be thrown. |
||||
126 | * |
||||
127 | * @return bool |
||||
128 | * True if item exists in the cache, false otherwise. |
||||
129 | */ |
||||
130 | public function hasItem($key) |
||||
131 | { |
||||
132 | if ( ! is_string($key)) { |
||||
0 ignored issues
–
show
|
|||||
133 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION'); |
||||
134 | } |
||||
135 | |||||
136 | return (bool)$this->memcached->get($this->prefixKey . $key); |
||||
137 | } |
||||
138 | |||||
139 | // ------------------------------------------------------------------------ |
||||
140 | |||||
141 | /** |
||||
142 | * ItemPool::clear |
||||
143 | * |
||||
144 | * Deletes all items in the pool. |
||||
145 | * |
||||
146 | * @return bool |
||||
147 | * True if the pool was successfully cleared. False if there was an error. |
||||
148 | */ |
||||
149 | public function clear() |
||||
150 | { |
||||
151 | return $this->memcached->flush(); |
||||
152 | } |
||||
153 | |||||
154 | // ------------------------------------------------------------------------ |
||||
155 | |||||
156 | /** |
||||
157 | * ItemPool::deleteItem |
||||
158 | * |
||||
159 | * Removes the item from the pool. |
||||
160 | * |
||||
161 | * @param string $key |
||||
162 | * The key to delete. |
||||
163 | * |
||||
164 | * @throws InvalidArgumentException |
||||
165 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||||
166 | * MUST be thrown. |
||||
167 | * |
||||
168 | * @return bool |
||||
169 | * True if the item was successfully removed. False if there was an error. |
||||
170 | */ |
||||
171 | public function deleteItem($key) |
||||
172 | { |
||||
173 | if ( ! is_string($key)) { |
||||
0 ignored issues
–
show
|
|||||
174 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION'); |
||||
175 | } |
||||
176 | |||||
177 | return $this->memcached->delete($this->prefixKey . $key); |
||||
178 | } |
||||
179 | |||||
180 | // ------------------------------------------------------------------------ |
||||
181 | |||||
182 | /** |
||||
183 | * CacheItemPoolInterface::deleteItems |
||||
184 | * |
||||
185 | * Removes multiple items from the pool. |
||||
186 | * |
||||
187 | * @param string[] $keys |
||||
188 | * An array of keys that should be removed from the pool. |
||||
189 | * |
||||
190 | * @throws InvalidArgumentException |
||||
191 | * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
||||
192 | * MUST be thrown. |
||||
193 | * |
||||
194 | * @return bool |
||||
195 | * True if the items were successfully removed. False if there was an error. |
||||
196 | */ |
||||
197 | public function deleteItems(array $keys) |
||||
198 | { |
||||
199 | if ( ! is_array($keys)) { |
||||
0 ignored issues
–
show
|
|||||
200 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_ARRAY_CACHE_EXCEPTION'); |
||||
201 | } |
||||
202 | |||||
203 | $keys = array_map( |
||||
204 | function ($key) { |
||||
205 | return $this->prefixKey . $key; |
||||
206 | }, |
||||
207 | $keys |
||||
208 | ); |
||||
209 | |||||
210 | return $this->memcached->deleteMulti($keys); |
||||
211 | } |
||||
212 | |||||
213 | // ------------------------------------------------------------------------ |
||||
214 | |||||
215 | /** |
||||
216 | * ItemPool::save |
||||
217 | * |
||||
218 | * Persists a cache item immediately. |
||||
219 | * |
||||
220 | * @param CacheItemInterface $item |
||||
221 | * The cache item to save. |
||||
222 | * |
||||
223 | * @return bool |
||||
224 | * True if the item was successfully persisted. False if there was an error. |
||||
225 | */ |
||||
226 | public function save(CacheItemInterface $item) |
||||
227 | { |
||||
228 | $metadata = $item->getMetadata(); |
||||
229 | $metadata[ 'data' ] = $item->get(); |
||||
230 | |||||
231 | return $this->memcached->set($this->prefixKey . $item->getKey(), $metadata, $metadata[ 'ttl' ]); |
||||
232 | } |
||||
233 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths