Completed
Pull Request — master (#554)
by Alejandro
13:38
created

ShortUrlNotFoundException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromNotFoundShortCode() 0 16 3
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
    public static function fromNotFoundShortCode(string $shortCode, ?string $domain = null): self
21
    {
22
        $suffix = $domain === null ? '' : sprintf(' for domain "%s"', $domain);
23
        $e = new self(sprintf('No URL found with short code "%s"%s', $shortCode, $suffix));
24
25
        $e->detail = $e->getMessage();
26
        $e->title = self::TITLE;
27
        $e->type = self::TYPE;
28
        $e->status = StatusCodeInterface::STATUS_NOT_FOUND;
29
        $e->additional = ['shortCode' => $shortCode];
30
31
        if ($domain !== null) {
32
            $e->additional['domain'] = $domain;
33
        }
34
35
        return $e;
36
    }
37
}
38