Passed
Push — master ( ae4c71...a17aed )
by Dominik
01:58
created

Unauthorized::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 8
cts 8
cp 1
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 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 View Code Duplication
final class Unauthorized extends AbstractApiProblem
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
     * @param string|null $detail
24
     * @param string|null $instance
25
     */
26 2
    public function __construct(
27
        string $authorization,
28
        array $authorizationTypes,
29
        string $detail = null,
30
        string $instance = null
31
    ) {
32 2
        parent::__construct(
33 2
            'https://tools.ietf.org/html/rfc2616#section-10.4.2',
34 2
            401,
35 2
            'Unauthorized',
36
            $detail,
37
            $instance
38
        );
39
40 2
        $this->authorization = $authorization;
41 2
        $this->authorizationTypes = $authorizationTypes;
42 2
    }
43
44
    /**
45
     * @return array
46
     */
47 2
    public function getHeaders(): array
48
    {
49 2
        if ([] === $this->authorizationTypes) {
50 1
            return [];
51
        }
52
53 1
        return ['WWW-Authenticate' => implode(',', $this->authorizationTypes)];
54
    }
55
56
    /**
57
     * @return string
58
     */
59 2
    public function getAuthorization(): string
60
    {
61 2
        return $this->authorization;
62
    }
63
64
    /**
65
     * @return string[]
66
     */
67 2
    public function getAuthorizationTypes(): array
68
    {
69 2
        return $this->authorizationTypes;
70
    }
71
}
72