| Total Complexity | 4 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class BadRequestHandler implements BadRequestHandlerInterface |
||
| 14 | { |
||
| 15 | private ResponseFactoryInterface $responseFactory; |
||
| 16 | private ?ParserException $parserException = null; |
||
| 17 | |||
| 18 | 9 | public function __construct(ResponseFactoryInterface $responseFactory) |
|
| 21 | 9 | } |
|
| 22 | |||
| 23 | 3 | public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 24 | { |
||
| 25 | 3 | $response = $this->responseFactory->createResponse(Status::BAD_REQUEST); |
|
| 26 | 3 | $response->getBody()->write(Status::TEXTS[Status::BAD_REQUEST]); |
|
| 27 | |||
| 28 | 3 | if ($this->parserException !== null) { |
|
| 29 | 1 | $response->getBody()->write("\n" . $this->parserException->getMessage()); |
|
| 30 | } |
||
| 31 | |||
| 32 | 3 | return $response; |
|
| 33 | } |
||
| 34 | |||
| 35 | 1 | public function withParserException(ParserException $e): BadRequestHandlerInterface |
|
| 40 | } |
||
| 41 | } |
||
| 42 |