This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Madewithlove\IlluminatePsrCacheBridge\Laravel; |
||
3 | |||
4 | use DateTimeImmutable; |
||
5 | use Exception; |
||
6 | use Illuminate\Contracts\Cache\Repository; |
||
7 | use Madewithlove\IlluminatePsrCacheBridge\Exceptions\InvalidArgumentException; |
||
8 | use Psr\Cache\CacheItemInterface; |
||
9 | use Psr\Cache\CacheItemPoolInterface; |
||
10 | |||
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) |
|
27 | { |
||
28 | 143 | $this->repository = $repository; |
|
29 | 143 | } |
|
30 | |||
31 | /** |
||
32 | * Destructor. |
||
33 | */ |
||
34 | 23 | public function __destruct() |
|
35 | { |
||
36 | 23 | $this->commit(); |
|
37 | 23 | } |
|
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 78 | public function getItem($key) |
|
43 | { |
||
44 | 78 | $this->validateKey($key); |
|
45 | |||
46 | 61 | if (isset($this->deferred[$key])) { |
|
47 | 5 | return clone($this->deferred[$key]); |
|
48 | 61 | } elseif ($this->repository->has($key)) { |
|
49 | 27 | return new CacheItem($key, unserialize($this->repository->get($key)), true); |
|
50 | } else { |
||
51 | 59 | return new CacheItem($key); |
|
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 22 | public function getItems(array $keys = array()) |
|
59 | { |
||
60 | return array_combine($keys, array_map(function($key) { |
||
61 | 20 | return $this->getItem($key); |
|
62 | 22 | }, $keys)); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 35 | public function hasItem($key) |
|
69 | { |
||
70 | 35 | $this->validateKey($key); |
|
71 | |||
72 | 17 | if (isset($this->deferred[$key])) { |
|
73 | 3 | $item = $this->deferred[$key]; |
|
74 | 3 | $expiresAt = $this->getExpiresAt($item); |
|
0 ignored issues
–
show
|
|||
75 | |||
76 | 3 | if (!$expiresAt) { |
|
77 | 1 | return true; |
|
78 | } |
||
79 | |||
80 | 2 | return $expiresAt > new DateTimeImmutable(); |
|
81 | } |
||
82 | |||
83 | 14 | return $this->repository->has($key); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 123 | public function clear() |
|
90 | { |
||
91 | try { |
||
92 | 123 | $this->deferred = []; |
|
93 | 123 | $store = $this->repository; |
|
94 | /* @var \Illuminate\Contracts\Cache\Store $store */ |
||
95 | 123 | $store->flush(); |
|
96 | 1 | } catch (Exception $exception) { |
|
97 | 1 | return false; |
|
98 | } |
||
99 | |||
100 | 122 | return true; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | 26 | public function deleteItem($key) |
|
107 | { |
||
108 | 26 | $this->validateKey($key); |
|
109 | |||
110 | 8 | unset($this->deferred[$key]); |
|
111 | |||
112 | 8 | if (!$this->hasItem($key)) { |
|
113 | 5 | return true; |
|
114 | } |
||
115 | |||
116 | 5 | return $this->repository->forget($key); |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | 22 | public function deleteItems(array $keys) |
|
123 | { |
||
124 | // Validating all keys first. |
||
125 | 22 | foreach ($keys as $key) { |
|
126 | 21 | $this->validateKey($key); |
|
127 | } |
||
128 | |||
129 | 4 | $success = true; |
|
130 | |||
131 | 4 | foreach ($keys as $key) { |
|
132 | 3 | $success = $success && $this->deleteItem($key); |
|
133 | } |
||
134 | |||
135 | 4 | return $success; |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | 36 | public function save(CacheItemInterface $item) |
|
142 | { |
||
143 | 36 | $expiresAt = $this->getExpiresAt($item); |
|
0 ignored issues
–
show
$item of type object<Psr\Cache\CacheItemInterface> is not a sub-type of object<Madewithlove\Illu...idge\Laravel\CacheItem> . It seems like you assume a concrete implementation of the interface Psr\Cache\CacheItemInterface to be always present.
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. ![]() |
|||
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) |
|
176 | { |
||
177 | 13 | $expiresAt = $this->getExpiresAt($item); |
|
0 ignored issues
–
show
$item of type object<Psr\Cache\CacheItemInterface> is not a sub-type of object<Madewithlove\Illu...idge\Laravel\CacheItem> . It seems like you assume a concrete implementation of the interface Psr\Cache\CacheItemInterface to be always present.
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. ![]() |
|||
178 | |||
179 | 13 | if ($expiresAt && ($expiresAt < new DateTimeImmutable())) { |
|
180 | 1 | return false; |
|
181 | } |
||
182 | |||
183 | 12 | $item = (new CacheItem($item->getKey(), $item->get(), true))->expiresAt($expiresAt); |
|
184 | |||
185 | 12 | $this->deferred[$item->getKey()] = $item; |
|
186 | |||
187 | 12 | return true; |
|
188 | } |
||
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | 31 | public function commit() |
|
194 | { |
||
195 | 31 | $success = true; |
|
196 | |||
197 | 31 | foreach ($this->deferred as $key => $item) { |
|
198 | 9 | $success = $success && $this->save($item); |
|
199 | } |
||
200 | |||
201 | 31 | $this->deferred = []; |
|
202 | |||
203 | 31 | return $success; |
|
204 | } |
||
205 | |||
206 | /** |
||
207 | * @param string $key |
||
208 | * |
||
209 | * @throws \Psr\Cache\InvalidArgumentException |
||
210 | */ |
||
211 | 137 | private function validateKey($key) |
|
212 | { |
||
213 | 137 | if (!is_string($key) || preg_match('#[{}\(\)/\\\\@:]#', $key)) { |
|
214 | 88 | throw new InvalidArgumentException(); |
|
215 | } |
||
216 | 84 | } |
|
217 | |||
218 | /** |
||
219 | * @param \Madewithlove\IlluminatePsrCacheBridge\Laravel\CacheItem $item |
||
220 | * |
||
221 | * @return \DateTimeInterface |
||
222 | */ |
||
223 | 40 | private function getExpiresAt(CacheItem $item) |
|
224 | { |
||
225 | 40 | return $item->getExpiresAt(); |
|
226 | } |
||
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.