Total Complexity | 10 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
5 | final class RedirectView implements ViewInterface |
||
6 | { |
||
7 | private array $headers = []; |
||
8 | |||
9 | 3 | public function __construct(string $location, private readonly int $statusCode = 302) |
|
10 | { |
||
11 | 3 | if ($statusCode < 300 || $statusCode >= 400) { |
|
12 | 1 | throw new \InvalidArgumentException('Redirect must have status code between 300-399'); |
|
13 | } |
||
14 | |||
15 | 2 | $this->setHeader('Location', $location); |
|
16 | } |
||
17 | |||
18 | 2 | public function getStatusCode(): int |
|
19 | { |
||
20 | 2 | return $this->statusCode; |
|
21 | } |
||
22 | |||
23 | 1 | public function getContentType(): string |
|
24 | { |
||
25 | 1 | throw new \RuntimeException('No content-type allowed on RedirectView'); |
|
26 | } |
||
27 | |||
28 | 2 | public function getHeaders(): array |
|
29 | { |
||
30 | 2 | return $this->headers; |
|
31 | } |
||
32 | |||
33 | 2 | public function setHeader(string $key, string $value): void |
|
34 | { |
||
35 | 2 | $this->headers[$key] = $value; |
|
36 | } |
||
37 | |||
38 | 1 | public function getTemplate(): string |
|
41 | } |
||
42 | |||
43 | 1 | public function getParameters(): array |
|
46 | } |
||
47 | |||
48 | 1 | public function setParameter(string $key, $value): void |
|
49 | { |
||
50 | 1 | throw new \RuntimeException('No parameters allowed on RedirectView'); |
|
53 |