Completed
Push — master ( 038254...115ca0 )
by Alejandro
06:27
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 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