| Conditions | 6 |
| Paths | 15 |
| Total Lines | 26 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 6 |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 16 | 9 | public function dispatch(callable $controller, array $vars, Route $route = null) |
|
| 17 | { |
||
| 18 | try { |
||
| 19 | 9 | $response = call_user_func_array($controller, [ |
|
| 20 | 9 | $this->getRequest(), |
|
| 21 | $vars |
||
| 22 | 9 | ]); |
|
| 23 | |||
| 24 | 6 | if (is_array($response) || $response instanceof ArrayObject) { |
|
| 25 | 3 | $body = json_encode($response); |
|
| 26 | 3 | $response = $this->getResponse(); |
|
| 27 | |||
| 28 | 3 | if ($response->getBody()->isWritable()) { |
|
| 29 | 3 | $response->getBody()->write($body); |
|
| 30 | 3 | } |
|
| 31 | 3 | } |
|
| 32 | |||
| 33 | 6 | if ($response instanceof ResponseInterface) { |
|
| 34 | 3 | return $response->withAddedHeader('content-type', 'application/json'); |
|
| 35 | } |
||
| 36 | 6 | } catch (HttpException $e) { |
|
| 37 | 3 | return $e->buildJsonResponse($this->getResponse()); |
|
| 38 | } |
||
| 39 | |||
| 40 | 3 | throw new RuntimeException('Unable to build a json response from controller return value.'); |
|
| 41 | } |
||
| 42 | } |
||
| 43 |