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

InvalidShortCodeException::fromNotFoundShortCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 1
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 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