IP   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A checkInRange() 0 4 1
A getLong() 0 3 1
A getIP() 0 3 1
A isIPv4() 0 3 1
A __construct() 0 3 1
A __toString() 0 3 1
A fromLong() 0 3 1
A isIPv6() 0 3 1
1
<?php
2
3
namespace Bavix\IP;
4
5
class IP
6
{
7
8
    /**
9
     * @var string
10
     */
11
    protected $ip;
12
13
    /**
14
     * Ip constructor.
15
     * @param string $ip
16
     */
17
    public function __construct(string $ip)
18
    {
19
        $this->ip = $ip;
20
    }
21
22
    /**
23
     * @param string $long
24
     * @return Ip
25
     */
26
    public static function fromLong(string $long): self
27
    {
28
        return new static(Util::long2ip($long));
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getLong(): string
35
    {
36
        return Util::ip2long($this->ip);
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getIP(): string
43
    {
44
        return $this->ip;
45
    }
46
47
    /**
48
     * @return bool
49
     */
50
    public function isIPv4(): bool
51
    {
52
        return Util::isIPv4($this->ip);
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function isIPv6(): bool
59
    {
60
        return Util::isIPv6($this->ip);
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function __toString(): string
67
    {
68
        return $this->ip;
69
    }
70
71
    /**
72
     * @param string $subnet
73
     * @return bool
74
     */
75
    public function checkInRange(string $subnet): bool
76
    {
77
        return RangeUtil::sharedInstance()
78
            ->check($this->ip, $subnet);
79
    }
80
81
}
82