1 | <?php |
||
14 | final class InMemoryCache implements CacheInterface |
||
15 | { |
||
16 | use KeyValidatorTrait; |
||
17 | use TTLValidatorTrait; |
||
18 | |||
19 | /** |
||
20 | * @var ArrayObject |
||
21 | */ |
||
22 | private $cache; |
||
23 | |||
24 | /** |
||
25 | * Construct a new instance of InMemoryCache. |
||
26 | * |
||
27 | * @param ArrayAccess $cache Initial cache container. |
||
28 | */ |
||
29 | public function __construct(ArrayAccess $cache = null) |
||
33 | |||
34 | /** |
||
35 | * Fetches a value from the cache. |
||
36 | * |
||
37 | * @param string $key The unique key of this item in the cache. |
||
38 | * @param mixed $default Default value to return if the key does not exist. |
||
39 | * |
||
40 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
||
41 | * |
||
42 | * @throws InvalidArgumentException Thrown if the $key string is not a legal value. |
||
43 | */ |
||
44 | public function get($key, $default = null)//@codingStandardsIgnoreLine Interface does not define type-hints or return |
||
59 | |||
60 | /** |
||
61 | * Obtains multiple cache items by their unique keys. |
||
62 | * |
||
63 | * @param iterable $keys A list of keys that can obtained in a single operation. |
||
64 | * @param mixed $default Default value to return for keys that do not exist. |
||
65 | * |
||
66 | * @return array List of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
||
67 | * |
||
68 | * @throws InvalidArgumentException Thrown if the $key string is not a legal value. |
||
69 | */ |
||
70 | public function getMultiple($keys, $default = null)//@codingStandardsIgnoreLine Interface does not define type-hints or return |
||
79 | |||
80 | /** |
||
81 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
||
82 | * |
||
83 | * @param string $key The key of the item to store. |
||
84 | * @param mixed $value The value of the item to store, must be serializable. |
||
85 | * @param null|integer|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
86 | * the driver supports TTL then the library may set a default value |
||
87 | * for it or let the driver take care of that. |
||
88 | * |
||
89 | * @return boolean True on success and false on failure. |
||
90 | * |
||
91 | * @throws InvalidArgumentException Thrown if the $key string is not a legal value. |
||
92 | */ |
||
93 | public function set($key, $value, $ttl = null)//@codingStandardsIgnoreLine Interface does not define type-hints or return |
||
100 | |||
101 | /** |
||
102 | * Persists a set of key => value pairs in the cache, with an optional TTL. |
||
103 | * |
||
104 | * @param iterable $values A list of key => value pairs for a multiple-set operation. |
||
105 | * @param null|integer|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
106 | * the driver supports TTL then the library may set a default value |
||
107 | * for it or let the driver take care of that. |
||
108 | * |
||
109 | * @return boolean True on success and false on failure. |
||
110 | * |
||
111 | * @throws InvalidArgumentException Thrown if $values is neither an array nor a Traversable, |
||
112 | * or if any of the $values are not a legal value. |
||
113 | */ |
||
114 | public function setMultiple($values, $ttl = null)//@codingStandardsIgnoreLine Interface does not define type-hints or return |
||
126 | |||
127 | /** |
||
128 | * Delete an item from the cache by its unique key. |
||
129 | * |
||
130 | * @param string $key The unique cache key of the item to delete. |
||
131 | * |
||
132 | * @return boolean True if the item was successfully removed. False if there was an error. |
||
133 | * |
||
134 | * @throws InvalidArgumentException Thrown if the $key string is not a legal value. |
||
135 | */ |
||
136 | public function delete($key)//@codingStandardsIgnoreLine Interface does not define type-hints or return |
||
142 | |||
143 | /** |
||
144 | * Deletes multiple cache items in a single operation. |
||
145 | * |
||
146 | * @param iterable $keys A list of string-based keys to be deleted. |
||
147 | * |
||
148 | * @return boolean True if the items were successfully removed. False if there was an error. |
||
149 | * |
||
150 | * @throws InvalidArgumentException Thrown if $keys is neither an array nor a Traversable, |
||
151 | * or if any of the $keys are not a legal value. |
||
152 | */ |
||
153 | public function deleteMultiple($keys)//@codingStandardsIgnoreLine Interface does not define type-hints |
||
162 | |||
163 | /** |
||
164 | * Wipes clean the entire cache's keys. |
||
165 | * |
||
166 | * @return boolean True on success and false on failure. |
||
167 | */ |
||
168 | public function clear()//@codingStandardsIgnoreLine Interface does not define type-hints or return |
||
173 | |||
174 | /** |
||
175 | * Determines whether an item is present in the cache. |
||
176 | * |
||
177 | * NOTE: It is recommended that has() is only to be used for cache warming type purposes |
||
178 | * and not to be used within your live applications operations for get/set, as this method |
||
179 | * is subject to a race condition where your has() will return true and immediately after, |
||
180 | * another script can remove it making the state of your app out of date. |
||
181 | * |
||
182 | * @param string $key The cache item key. |
||
183 | * |
||
184 | * @return boolean |
||
185 | * |
||
186 | * @throws InvalidArgumentException Thrown if the $key string is not a legal value. |
||
187 | */ |
||
188 | public function has($key) //@codingStandardsIgnoreLine Interface does not define type-hints |
||
193 | |||
194 | /** |
||
195 | * Converts the given time to live value to a DataTime instance; |
||
196 | * |
||
197 | * @param mixed $ttl The time-to-live value to validate. |
||
198 | * |
||
199 | * @return integer |
||
200 | */ |
||
201 | private function getExpiration($ttl) : int |
||
213 | } |
||
214 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.