NonUniqueSlugException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromSlug() 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 Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
9
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
10
11
use function sprintf;
12
13
class NonUniqueSlugException extends InvalidArgumentException implements ProblemDetailsExceptionInterface
14
{
15
    use CommonProblemDetailsExceptionTrait;
16
17
    private const TITLE = 'Invalid custom slug';
18
    private const TYPE = 'INVALID_SLUG';
19
20 5
    public static function fromSlug(string $slug, ?string $domain = null): self
21
    {
22 5
        $suffix = $domain === null ? '' : sprintf(' for domain "%s"', $domain);
23 5
        $e = new self(sprintf('Provided slug "%s" is already in use%s.', $slug, $suffix));
24
25 5
        $e->detail = $e->getMessage();
26 5
        $e->title = self::TITLE;
27 5
        $e->type = self::TYPE;
28 5
        $e->status = StatusCodeInterface::STATUS_BAD_REQUEST;
29 5
        $e->additional = ['customSlug' => $slug];
30
31 5
        if ($domain !== null) {
32 2
            $e->additional['domain'] = $domain;
33
        }
34
35 5
        return $e;
36
    }
37
}
38