Total Complexity | 8 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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 |
||
79 | } |
||
80 | |||
81 | } |
||
82 |