Completed
Push — master ( 224127...d5dc6c )
by Alejandro
28s
created

VerifyAuthenticationException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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