Completed
Pull Request — master (#199)
by Alejandro
03:59
created

DeleteShortUrlException::fromVisitsThreshold()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
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