Total Complexity | 8 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
10 | final class JsonRequestParserMiddleware implements MiddlewareInterface |
||
11 | { |
||
12 | /** @param string[] $jsonContentTypes array of regexes to check against content-types */ |
||
13 | 7 | public function __construct( |
|
16 | |||
17 | 6 | public function process(ServerRequestInterface $request, RequestHandlerInterface $requestHandler): ResponseInterface |
|
18 | { |
||
19 | 6 | if ($this->isJsonRequest($request->getHeaderLine('Content-Type'))) { |
|
20 | 5 | $request = $request->withParsedBody($this->parseBody($request)); |
|
21 | } |
||
22 | 5 | return $requestHandler->handle($request); |
|
23 | } |
||
24 | |||
25 | 6 | private function isJsonRequest(string $requestContentType) : bool |
|
33 | } |
||
34 | |||
35 | 5 | private function parseBody(ServerRequestInterface $request) : array |
|
45 |