Test Failed
Push — master ( 395abb...b942d2 )
by Jelmer
12:58
created

RedirectView   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 48
ccs 19
cts 19
cp 1
rs 10
wmc 10

8 Methods

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