ValidateIp::getHostName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
nc 1
nop 1
dl 0
loc 4
c 1
b 0
f 0
cc 1
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bjos\Validate;
4
5
class ValidateIp
6
{
7
8
    /**
9
     * This is the index method action, it handles:
10
     * IP validation of the queryparameter ip.
11
     *
12
     * @return bool
13
     */
14 19
    public function validate(string $ipAdr = null) : bool
15
    {
16 19
        if ($ipAdr) {
17 17
            if (filter_var($ipAdr, FILTER_VALIDATE_IP)) {
18 7
                return true;
19
            } else {
20 10
                return false;
21
            }
22
        } else {
23 2
            return false;
24
        }
25
    }
26
27
28
    /**
29
     * This is the index method action, it handles:
30
     * IP validation of the queryparameter ip.
31
     *
32
     * @return string|void  $type
33
     */
34 6
    public function getIpType(string $ipAdr)
35
    {
36 6
        $type = null;
37
38 6
        if (filter_var($ipAdr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
39 3
            $type = "IPV4";
40 3
        } elseif (filter_var($ipAdr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
41 2
            $type = "IPV6";
42
        }
43
44 6
        return $type;
45
    }
46
47
    /**
48
     * This is the index method action, it handles:
49
     * IP validation of the queryparameter ip.
50
     *
51
     * @return string $host
52
     */
53 4
    public function getHostName(string $ipAdr) : string
54
    {
55 4
        $host = gethostbyaddr($ipAdr);
56 4
        return $host;
57
    }
58
}
59