Completed
Pull Request — master (#554)
by Alejandro
05:47
created

InvalidShortCodeException   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromNotFoundShortCode() 0 10 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
    private 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
24 2
        $e->detail = $e->getMessage();
25 2
        $e->title = self::TITLE;
26 2
        $e->type = self::TYPE;
27 2
        $e->status = StatusCodeInterface::STATUS_NOT_FOUND;
28
29 2
        return $e;
30
    }
31
}
32