Passed
Push — master ( 748bbc...6ff058 )
by Dominik
02:33
created

Unauthorized::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 $authorizationTypes = [];
15
16
    /**
17
     * @param string[]    $authorizationTypes
18
     * @param string|null $detail
19
     * @param string|null $instance
20
     */
21 2
    public function __construct(array $authorizationTypes, string $detail = null, string $instance = null)
22
    {
23 2
        parent::__construct(
24 2
            'https://tools.ietf.org/html/rfc2616#section-10.4.2',
25 2
            401,
26 2
            'Unauthorized',
27
            $detail,
28
            $instance
29
        );
30
31 2
        $this->authorizationTypes = $authorizationTypes;
32 2
    }
33
34
    /**
35
     * @return array
36
     */
37 2
    public function getHeaders(): array
38
    {
39 2
        if ([] === $this->authorizationTypes) {
40 1
            return [];
41
        }
42
43 1
        return ['WWW-Authenticate' => implode(',', $this->authorizationTypes)];
44
    }
45
46
    /**
47
     * @return string[]
48
     */
49 2
    public function getAuthorizationTypes(): array
50
    {
51 2
        return $this->authorizationTypes;
52
    }
53
}
54