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