1 | <?php |
||
11 | class CacheItemPool implements CacheItemPoolInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var \Illuminate\Contracts\Cache\Repository |
||
15 | */ |
||
16 | private $repository; |
||
17 | |||
18 | /** |
||
19 | * @var \Psr\Cache\CacheItemInterface[] |
||
20 | */ |
||
21 | private $deferred = []; |
||
22 | |||
23 | /** |
||
24 | * @param \Illuminate\Contracts\Cache\Repository $repository |
||
25 | */ |
||
26 | 143 | public function __construct(Repository $repository) |
|
30 | |||
31 | /** |
||
32 | * Destructor. |
||
33 | */ |
||
34 | 23 | public function __destruct() |
|
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 78 | public function getItem($key) |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 22 | public function getItems(array $keys = array()) |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 35 | public function hasItem($key) |
|
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 123 | public function clear() |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | 26 | public function deleteItem($key) |
|
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | 22 | public function deleteItems(array $keys) |
|
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | 36 | public function save(CacheItemInterface $item) |
|
142 | { |
||
143 | 36 | $expiresAt = $this->getExpiresAt($item); |
|
144 | |||
145 | 36 | if (!$expiresAt) { |
|
146 | try { |
||
147 | 31 | $this->repository->forever($item->getKey(), serialize($item->get())); |
|
148 | 1 | } catch (Exception $exception) { |
|
149 | 1 | return false; |
|
150 | } |
||
151 | |||
152 | 30 | return true; |
|
153 | } |
||
154 | |||
155 | 5 | $lifetime = LifetimeHelper::computeLifetime($expiresAt); |
|
156 | |||
157 | 5 | if ($lifetime <= 0) { |
|
158 | 1 | $this->repository->forget($item->getKey()); |
|
159 | |||
160 | 1 | return false; |
|
161 | } |
||
162 | |||
163 | try { |
||
164 | 5 | $this->repository->put($item->getKey(), serialize($item->get()), $lifetime); |
|
165 | } catch (Exception $exception) { |
||
166 | return false; |
||
167 | } |
||
168 | |||
169 | 5 | return true; |
|
170 | } |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | 13 | public function saveDeferred(CacheItemInterface $item) |
|
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | 31 | public function commit() |
|
205 | |||
206 | /** |
||
207 | * @param string $key |
||
208 | * |
||
209 | * @throws \Psr\Cache\InvalidArgumentException |
||
210 | */ |
||
211 | 137 | private function validateKey($key) |
|
217 | |||
218 | /** |
||
219 | * @param \Madewithlove\IlluminatePsrCacheBridge\Laravel\CacheItem $item |
||
220 | * |
||
221 | * @return \DateTimeInterface |
||
222 | */ |
||
223 | 40 | private function getExpiresAt(CacheItem $item) |
|
227 | } |
||
228 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.