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

InvalidShortCodeException   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromNotFoundShortCode() 0 13 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