| Conditions | 5 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | #[\Override] |
||
| 26 | public function invoke(AbstractRequest $request): ResourceObject |
||
| 27 | { |
||
| 28 | $callable = [$request->resourceObject, 'on' . ucfirst($request->method)]; |
||
| 29 | if (! is_callable($callable)) { |
||
| 30 | // OPTIONS or HEAD |
||
| 31 | return ($this->extraMethod)($request, $this); |
||
| 32 | } |
||
| 33 | |||
| 34 | $params = $this->params->getParameters($callable, $request->query); |
||
| 35 | /** @psalm-suppress MixedAssignment */ |
||
| 36 | try { |
||
| 37 | $response = call_user_func_array($callable, $params); |
||
| 38 | } catch (Throwable $e) { |
||
| 39 | if ($e::class === \TypeError::class) { |
||
| 40 | throw new BadRequestException('Invalid parameter type', Code::BAD_REQUEST, $e); |
||
| 41 | } |
||
| 42 | throw $e; |
||
| 43 | } |
||
| 44 | if (! $response instanceof ResourceObject) { |
||
| 45 | $request->resourceObject->body = $response; |
||
| 46 | $response = $request->resourceObject; |
||
| 47 | } |
||
| 48 | |||
| 49 | ($this->logger)($response); |
||
| 50 | |||
| 51 | return $response; |
||
| 52 | } |
||
| 54 |