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

InvalidShortCodeException::fromCharset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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