IpValidation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 39
c 1
b 0
f 0
ccs 13
cts 13
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getProtocol() 0 10 3
A isIpValid() 0 6 2
A getDomain() 0 3 1
1
<?php
2
namespace Blixter\IpValidate;
3
4
use Anax\Commons\ContainerInjectableInterface;
5
use Anax\Commons\ContainerInjectableTrait;
6
7
/**
8
 * A sample controller to show how a controller class can be implemented.
9
 * The controller will be injected with $di if implementing the interface
10
 * ContainerInjectableInterface, like this sample class does.
11
 * The controller is mounted on a particular route and can then handle all
12
 * requests for that mount point.
13
 *
14
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
15
 */
16
class IpValidation implements ContainerInjectableInterface
17
{
18
    use ContainerInjectableTrait;
19
    /**
20
     * Check if ip-address is valid
21
     *
22
     * @return bool
23
     */
24 13
    public function isIpValid($ipAddress)
25
    {
26 13
        if (filter_var($ipAddress, FILTER_VALIDATE_IP)) {
27 7
            return true;
28
        }
29 6
        return false;
30
    }
31
    /**
32
     * Return if IPv4 or IPv6 protocol
33
     *
34
     * @return string
35
     */
36 3
    public function getProtocol($ipAddress)
37
    {
38 3
        $protocol = "";
39 3
        if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
40 2
            $protocol = "IPv4";
41
        }
42 3
        if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
43 1
            $protocol = "IPv6";
44
        }
45 3
        return $protocol;
46
    }
47
    /**
48
     * Return domain of ip-address
49
     *
50
     * @return string
51
     */
52 4
    public function getDomain($ipAddress)
53
    {
54 4
        return gethostbyaddr($ipAddress);
55
    }
56
}
57