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

ShortUrlNotFoundException::fromNotFoundShortCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 2
rs 10
c 0
b 0
f 0
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