Completed
Push — master ( 038254...115ca0 )
by Alejandro
06:27
created

InvalidShortCodeException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 15
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNotFoundShortCode() 0 3 1
A fromCharset() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Exception;
6
7
use Throwable;
8
9
use function sprintf;
10
11
class InvalidShortCodeException extends RuntimeException
12
{
13 2
    public static function fromCharset(string $shortCode, string $charSet, ?Throwable $previous = null): self
14
    {
15 2
        $code = $previous !== null ? $previous->getCode() : -1;
16 2
        return new static(
17 2
            sprintf('Provided short code "%s" does not match the char set "%s"', $shortCode, $charSet),
18 2
            $code,
19 2
            $previous
20
        );
21
    }
22
23 2
    public static function fromNotFoundShortCode(string $shortCode): self
24
    {
25 2
        return new static(sprintf('Provided short code "%s" does not belong to a short URL', $shortCode));
26
    }
27
}
28