| Conditions | 3 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 3.0021 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | 3 | public function handle(ServerRequestInterface $request, DelegateInterface $next) |
|
| 29 | { |
||
| 30 | 3 | $action = $request->getMethod(); |
|
| 31 | 3 | if ('GET' !== $action) { |
|
| 32 | return $next->next($request); |
||
| 33 | } |
||
| 34 | |||
| 35 | 3 | $key = md5($request->getUri()->getPath()); |
|
| 36 | 3 | $cache = cache()->getItem($key); |
|
| 37 | 3 | if ($cache->isHit()) { |
|
| 38 | 2 | $value = Json::decode($cache->get()); |
|
| 39 | |||
| 40 | 2 | return json($value) |
|
|
|
|||
| 41 | 2 | ->withHeader('X-Cache', $key); |
|
| 42 | } |
||
| 43 | 1 | $response = $next->next($request); |
|
| 44 | 1 | $cache->set((string) $response->getBody()); |
|
| 45 | |||
| 46 | 1 | $expireAt = DateObject::createFromTimestamp(time() + config()->get('common.cache.lifetime', 60)); |
|
| 47 | 1 | $cache->expiresAt($expireAt); |
|
| 48 | 1 | cache()->save($cache); |
|
| 49 | |||
| 50 | 1 | return $response->withExpires($expireAt); |
|
| 51 | } |
||
| 52 | } |
||
| 53 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: