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

DeleteShortUrlException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromVisitsThreshold() 0 6 1
A getVisitsThreshold() 0 3 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