Unauthorized   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 49
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 3 1
A __construct() 0 16 1
A getAuthorization() 0 3 1
A getAuthorizationTypes() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiHttp\ApiProblem\ClientError;
6
7
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;
8
9
final class Unauthorized extends AbstractApiProblem
10
{
11
    /**
12
     * @var string
13
     */
14
    private $authorization;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $authorizationTypes = [];
20
21
    /**
22
     * @param string[] $authorizationTypes
23
     */
24
    public function __construct(
25
        string $authorization,
26 2
        array $authorizationTypes,
27
        string $detail = null,
28
        string $instance = null
29
    ) {
30
        parent::__construct(
31
            'https://tools.ietf.org/html/rfc2616#section-10.4.2',
32 2
            401,
33 2
            'Unauthorized',
34 2
            $detail,
35 2
            $instance
36
        );
37
38
        $this->authorization = $authorization;
39
        $this->authorizationTypes = $authorizationTypes;
40 2
    }
41 2
42 2
    public function getHeaders(): array
43
    {
44
        return ['WWW-Authenticate' => implode(',', $this->authorizationTypes)];
45
    }
46
47 2
    public function getAuthorization(): string
48
    {
49 2
        return $this->authorization;
50
    }
51
52
    /**
53
     * @return string[]
54
     */
55 2
    public function getAuthorizationTypes(): array
56
    {
57 2
        return $this->authorizationTypes;
58
    }
59
}
60