IPGeoValidator::getHost()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 * IP Validator
5
 */
6
7
namespace Hepa19\IPGeo;
8
9
/**
10
 * Validate IP Addresses
11
 *
12
 */
13
class IPGeoValidator
14
{
15
    /**
16
     * Returns if ip is valid
17
     *
18
     * @return bool
19
     */
20 7
    public function isValid($ip) : bool
21
    {
22 7
        if (filter_var($ip, FILTER_VALIDATE_IP)) {
23 6
            return true;
24
        }
25 1
        return false;
26
    }
27
28
29
30
    /**
31
     * Returns if ip is IPv4 or IPv6
32
     *
33
     * @return string|null
34
     */
35 8
    public function getProtocol($ip)
36
    {
37 8
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
38 5
            return "IPv4";
39 3
        } else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
40 2
            return "IPv6";
41
        }
42 1
        return null;
43
    }
44
45
46
47
    /**
48
     * Returns host
49
     *
50
     * @return string|void
51
     */
52 7
    public function getHost($ip)
53
    {
54 7
        if (filter_var($ip, FILTER_VALIDATE_IP)) {
55 6
            return gethostbyaddr($ip);
56
        }
57 1
    }
58
}
59