IpCannotBeLocatedException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A forLocalhost() 0 3 1
A forError() 0 6 1
A forEmptyAddress() 0 3 1
A isNonLocatableAddress() 0 3 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