Completed
Push — master ( 038254...115ca0 )
by Alejandro
06:27
created

VerifyAuthenticationException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getErrorCode() 0 3 1
A getPublicMessage() 0 3 1
A withError() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Rest\Exception;
6
7
use Throwable;
8
9
use function sprintf;
10
11
class VerifyAuthenticationException extends RuntimeException
12
{
13
    /** @var string */
14
    private $errorCode;
15
    /** @var string */
16
    private $publicMessage;
17
18 27
    public function __construct(
19
        string $errorCode,
20
        string $publicMessage,
21
        string $message = '',
22
        int $code = 0,
23
        ?Throwable $previous = null
24
    ) {
25 27
        parent::__construct($message, $code, $previous);
26 27
        $this->errorCode = $errorCode;
27 27
        $this->publicMessage = $publicMessage;
28
    }
29
30 15
    public static function withError(string $errorCode, string $publicMessage, ?Throwable $prev = null): self
31
    {
32 15
        return new self(
33 15
            $errorCode,
34 15
            $publicMessage,
35 15
            sprintf('Authentication verification failed with the public message "%s"', $publicMessage),
36 15
            0,
37 15
            $prev
38
        );
39
    }
40
41 23
    public function getErrorCode(): string
42
    {
43 23
        return $this->errorCode;
44
    }
45
46 23
    public function getPublicMessage(): string
47
    {
48 23
        return $this->publicMessage;
49
    }
50
}
51