Completed
Push — master ( 5b9784...ff8441 )
by Alejandro
12s
created

DeleteShortUrlException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromVisitsThreshold() 0 8 1
A getVisitsThreshold() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Exception;
5
6
use Throwable;
7
8
class DeleteShortUrlException extends RuntimeException
9
{
10
    /**
11
     * @var int
12
     */
13
    private $visitsThreshold;
14
15 16
    public function __construct(int $visitsThreshold, string $message = '', int $code = 0, Throwable $previous = null)
16
    {
17 16
        $this->visitsThreshold = $visitsThreshold;
18 16
        parent::__construct($message, $code, $previous);
19 16
    }
20
21 4
    public static function fromVisitsThreshold(int $threshold, string $shortCode): self
22
    {
23 4
        return new self($threshold, \sprintf(
24 4
            'Impossible to delete short URL with short code "%s" since it has more than "%s" visits.',
25 4
            $shortCode,
26 4
            $threshold
27
        ));
28
    }
29
30 13
    public function getVisitsThreshold(): int
31
    {
32 13
        return $this->visitsThreshold;
33
    }
34
}
35