Passed
Push — master ( f95b05...51b5c6 )
by Бабичев
01:28
created

IP::getIP()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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