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

DeleteShortUrlException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
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 DeleteShortUrlException extends RuntimeException
12
{
13
    /** @var int */
14
    private $visitsThreshold;
15
16 25
    public function __construct(int $visitsThreshold, string $message = '', int $code = 0, ?Throwable $previous = null)
17
    {
18 25
        $this->visitsThreshold = $visitsThreshold;
19 25
        parent::__construct($message, $code, $previous);
20
    }
21
22 11
    public static function fromVisitsThreshold(int $threshold, string $shortCode): self
23
    {
24 11
        return new self($threshold, sprintf(
25 11
            'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
26 11
            $shortCode,
27 11
            $threshold
28
        ));
29
    }
30
31 25
    public function getVisitsThreshold(): int
32
    {
33 25
        return $this->visitsThreshold;
34
    }
35
}
36