isNonLocatableAddress()   A
last analyzed

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 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Exception;
6
7
use Throwable;
8
9
class IpCannotBeLocatedException extends RuntimeException
10
{
11
    private bool $isNonLocatableAddress = true;
12
13 3
    public static function forEmptyAddress(): self
14
    {
15 3
        return new self('Ignored visit with no IP address');
16
    }
17
18 2
    public static function forLocalhost(): self
19
    {
20 2
        return new self('Ignored localhost address');
21
    }
22
23 7
    public static function forError(Throwable $e): self
24
    {
25 7
        $e = new self('An error occurred while locating IP', $e->getCode(), $e);
26 7
        $e->isNonLocatableAddress = false;
27
28 7
        return $e;
29
    }
30
31
    /**
32
     * Tells if this error belongs to an address that will never be possible locate
33
     */
34 11
    public function isNonLocatableAddress(): bool
35
    {
36 11
        return $this->isNonLocatableAddress;
37
    }
38
}
39