Completed
Push — master ( c70077...3d32a9 )
by Alejandro
16s queued 10s
created

IpCannotBeLocatedException::forError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Exception;
5
6
use Throwable;
7
8
class IpCannotBeLocatedException extends RuntimeException
9
{
10
    /** @var bool */
11
    private $isNonLocatableAddress;
12
13 14
    public function __construct(
14
        bool $isNonLocatableAddress,
15
        string $message,
16
        int $code = 0,
17
        ?Throwable $previous = null
18
    ) {
19 14
        $this->isNonLocatableAddress = $isNonLocatableAddress;
20 14
        parent::__construct($message, $code, $previous);
21
    }
22
23 3
    public static function forEmptyAddress(): self
24
    {
25 3
        return new self(true, 'Ignored visit with no IP address');
26
    }
27
28 2
    public static function forLocalhost(): self
29
    {
30 2
        return new self(true, 'Ignored localhost address');
31
    }
32
33 4
    public static function forError(Throwable $e): self
34
    {
35 4
        return new self(false, 'An error occurred while locating IP', $e->getCode(), $e);
36
    }
37
38
    /**
39
     * Tells if this error belongs to an address that will never be possible locate
40
     */
41 10
    public function isNonLocatableAddress(): bool
42
    {
43 10
        return $this->isNonLocatableAddress;
44
    }
45
}
46