| Total Complexity | 7 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | class RequestTransformerSubscriber implements EventSubscriberInterface |
||
| 20 | { |
||
| 21 | 2 | public static function getSubscribedEvents(): array |
|
| 22 | { |
||
| 23 | return [ |
||
| 24 | 2 | KernelEvents::REQUEST => ['onKernelRequest', 1023], |
|
| 25 | ]; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @Callback |
||
| 30 | * @see getSubscribedEvents() |
||
| 31 | * @param RequestEvent $event |
||
| 32 | */ |
||
| 33 | 9 | public function onKernelRequest(RequestEvent $event): void |
|
| 34 | { |
||
| 35 | 9 | $request = $event->getRequest(); |
|
| 36 | |||
| 37 | 9 | if (false === $this->supports($request)) { |
|
| 38 | 7 | return; |
|
| 39 | } |
||
| 40 | |||
| 41 | try { |
||
| 42 | /** @var array|scalar $data */ |
||
| 43 | 2 | $data = json_decode((string) $request->getContent(), true, 512, JSON_THROW_ON_ERROR); |
|
| 44 | |||
| 45 | 1 | if (is_array($data)) { |
|
| 46 | 1 | $request->request->replace($data); |
|
| 47 | } |
||
| 48 | 1 | } catch (JsonException $exception) { |
|
| 49 | 1 | throw new BadRequestHttpException($exception->getMessage()); |
|
| 50 | } |
||
| 51 | 1 | } |
|
| 52 | |||
| 53 | 9 | private function supports(Request $request): bool |
|
| 56 | } |
||
| 57 | } |
||
| 58 |