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