| Conditions | 4 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 4 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | 6 | public function onKernelView(GetResponseForControllerResultEvent $event) |
|
| 15 | { |
||
| 16 | 6 | if (! $event->getRequest()->attributes->get('_rest[encode_response]', false, true)) { |
|
| 17 | 2 | return; |
|
| 18 | } |
||
| 19 | |||
| 20 | 4 | $result = $event->getControllerResult(); |
|
| 21 | |||
| 22 | 4 | if (! $result instanceof Response) { |
|
| 23 | 4 | if (!is_array($result)) { |
|
| 24 | 2 | throw new \LogicException('Invalid controller result: array was expected.'); |
|
| 25 | } |
||
| 26 | |||
| 27 | 2 | $result = new JsonResponse($result); |
|
| 28 | 2 | } |
|
| 29 | |||
| 30 | 2 | $event->setResponse($result); |
|
| 31 | 2 | } |
|
| 32 | |||
| 38 |