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

VerifyAuthenticationException::getErrorCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 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