IpVerify::ipVerify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
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