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

ShortUrlNotFoundException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromNotFoundShortCode() 0 11 2
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 ShortUrlNotFoundException extends DomainException implements ProblemDetailsExceptionInterface
14
{
15
    use CommonProblemDetailsExceptionTrait;
16
17
    private const TITLE = 'Short URL not found';
18
    private const TYPE = 'INVALID_SHORTCODE';
19
20 3
    public static function fromNotFoundShortCode(string $shortCode, ?string $domain = null): self
21
    {
22 3
        $suffix = $domain === null ? '' : sprintf(' for domain "%s"', $domain);
23 3
        $e = new self(sprintf('No URL found with short code "%s"%s', $shortCode, $suffix));
24
25 3
        $e->detail = $e->getMessage();
26 3
        $e->title = self::TITLE;
27 3
        $e->type = self::TYPE;
28 3
        $e->status = StatusCodeInterface::STATUS_NOT_FOUND;
29
30 3
        return $e;
31
    }
32
}
33