Total Complexity | 3 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
24 | final class StatusCodeMiddleware implements MiddlewareInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | private $statusCode; |
||
30 | |||
31 | /** |
||
32 | * StatusCodeMiddleware constructor. |
||
33 | * |
||
34 | * @param int $statusCode |
||
35 | * |
||
36 | * @throws \ReflectionException |
||
37 | */ |
||
38 | public function __construct(int $statusCode) |
||
39 | { |
||
40 | $this->statusCode = $statusCode; |
||
41 | |||
42 | $reflection = new \ReflectionClass(StatusCodeInterface::class); |
||
43 | $allowedStatus = $reflection->getConstants(); |
||
44 | |||
45 | if (!\in_array($this->statusCode, $allowedStatus)) { |
||
46 | throw new \UnexpectedValueException('Invalid HTTP Status Code'); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
57 | } |
||
58 | } |
||
59 |