IpVerify   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 48
ccs 15
cts 15
cp 1
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ipVerify() 0 6 2
A getIpInfo() 0 9 3
A getDomain() 0 7 2
1
<?php
2
3
/**
4
 * Ip verifier.
5
 */
6
7
namespace Anax\IpVerify;
8
9
/**
10
 * Showing off a standard class with methods and properties.
11
 */
12
class IpVerify
13
{
14
    /**
15
     * Validates ip address.
16
     *
17
     * @return bool
18
     */
19
20 30
    public function ipVerify(string $ipAdress)
21
    {
22 30
        if (filter_var($ipAdress, FILTER_VALIDATE_IP)) {
23 26
            return true;
24
        } else {
25 4
            return false;
26
        }
27
    }
28
29
    /**
30
     * Validates ip address.
31
     *
32
     * @return string
33
     */
34
35 26
    public function getIpInfo(string $ipAdress)
36
    {
37
38 26
        if (filter_var($ipAdress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
39 22
            return "IPV4";
40 4
        } elseif (filter_var($ipAdress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
41 3
            return "IPV6";
42
        } else {
43 1
            return "n/a";
44
        }
45
    }
46
47
    /**
48
     * Gets domain.
49
     *
50
     * @return string
51
     */
52
53 26
    public function getDomain(string $ipAdress)
54
    {
55 26
        if ($this->ipVerify($ipAdress)) {
56 25
            $host = gethostbyaddr($ipAdress);
57 25
            return $host;
58
        } else {
59 1
            return "n/a";
60
        }
61
    }
62
}
63