Completed
Pull Request — master (#554)
by Alejandro
11:37 queued 08:50
created

fromExpectedTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Rest\Exception;
6
7
use Fig\Http\Message\StatusCodeInterface;
8
use Zend\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
9
use Zend\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
10
11
use function implode;
12
use function sprintf;
13
14
class MissingAuthenticationException extends RuntimeException implements ProblemDetailsExceptionInterface
15
{
16
    use CommonProblemDetailsExceptionTrait;
17
18
    private const TITLE = 'Invalid authorization';
19
    private const TYPE = 'INVALID_AUTHORIZATION';
20
21 1
    public static function fromExpectedTypes(array $expectedTypes): self
22
    {
23 1
        $e = new self(sprintf(
24 1
            'Expected one of the following authentication headers, but none were provided, ["%s"]',
25 1
            implode('", "', $expectedTypes)
26
        ));
27
28 1
        $e->detail = $e->getMessage();
29 1
        $e->title = self::TITLE;
30 1
        $e->type = self::TYPE;
31 1
        $e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
32 1
        $e->additional = ['expectedTypes' => $expectedTypes];
33
34 1
        return $e;
35
    }
36
}
37