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

IpCannotBeLocatedException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 11
cts 11
cp 1

5 Methods

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