Passed
Pull Request — master (#554)
by Alejandro
05:43
created

InvalidShortCodeException::fromNotFoundShortCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 9.9666
ccs 10
cts 10
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\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 InvalidShortCodeException extends RuntimeException implements ProblemDetailsExceptionInterface
14
{
15
    use CommonProblemDetailsExceptionTrait;
16
17
    public const TITLE = 'Invalid short code';
18
    public const TYPE = 'INVALID_SHORTCODE';
19
20 2
    public static function fromNotFoundShortCode(string $shortCode): self
21
    {
22 2
        $e = new self(sprintf('No URL found for short code "%s"', $shortCode));
23 2
        $e->detail = $e->getMessage();
24 2
        $e->title = self::TITLE;
25 2
        $e->type = self::TYPE;
26 2
        $e->status = StatusCodeInterface::STATUS_NOT_FOUND;
27 2
        $e->additional = [
28 2
            'error' => $e->type,
29 2
            'message' => $e->detail,
30
        ];
31
32 2
        return $e;
33
    }
34
}
35