Completed
Push — master ( a7d308...df23f2 )
by Alejandro
25s queued 11s
created

VerifyAuthenticationException::forInvalidApiKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
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 sprintf;
12
13
class VerifyAuthenticationException extends RuntimeException implements ProblemDetailsExceptionInterface
14
{
15
    use CommonProblemDetailsExceptionTrait;
16
17 2
    public static function forInvalidApiKey(): self
18
    {
19 2
        $e = new self('Provided API key does not exist or is invalid.');
20
21 2
        $e->detail = $e->getMessage();
22 2
        $e->title = 'Invalid API key';
23 2
        $e->type = 'INVALID_API_KEY';
24 2
        $e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
25
26 2
        return $e;
27
    }
28
29
    /** @deprecated */
30 1
    public static function forInvalidAuthToken(): self
31
    {
32 1
        $e = new self(
33
            'Missing or invalid auth token provided. Perform a new authentication request and send provided '
34 1
            . 'token on every new request on the Authorization header'
35
        );
36
37 1
        $e->detail = $e->getMessage();
38 1
        $e->title = 'Invalid auth token';
39 1
        $e->type = 'INVALID_AUTH_TOKEN';
40 1
        $e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
41
42 1
        return $e;
43
    }
44
45
    /** @deprecated */
46 1
    public static function forMissingAuthType(): self
47
    {
48 1
        $e = new self('You need to provide the Bearer type in the Authorization header.');
49
50 1
        $e->detail = $e->getMessage();
51 1
        $e->title = 'Invalid authorization';
52 1
        $e->type = 'INVALID_AUTHORIZATION';
53 1
        $e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
54
55 1
        return $e;
56
    }
57
58
    /** @deprecated */
59 1
    public static function forInvalidAuthType(string $providedType): self
60
    {
61 1
        $e = new self(sprintf('Provided authorization type %s is not supported. Use Bearer instead.', $providedType));
62
63 1
        $e->detail = $e->getMessage();
64 1
        $e->title = 'Invalid authorization';
65 1
        $e->type = 'INVALID_AUTHORIZATION';
66 1
        $e->status = StatusCodeInterface::STATUS_UNAUTHORIZED;
67
68 1
        return $e;
69
    }
70
}
71