IpValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
dl 0
loc 25
c 1
b 0
f 1
ccs 11
cts 11
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateIp() 0 19 3
1
<?php
2
3
namespace Anax\Models;
4
5
class IpValidator
6
{
7
    /**
8
     * model class for ip validation: parent class to GeoApi
9
     * used by IpController and IpToJSONController
10
     */
11 2
    public function validateIp($ipAdress)
12
    {
13 2
        if (filter_var($ipAdress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
14 2
            $res = "$ipAdress är en giltig IP4-adress.";
15 2
            $domain = "Domänen är: " . gethostbyaddr($ipAdress);
16 2
        } elseif (filter_var($ipAdress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
17 2
            $res = "$ipAdress är en giltig IP6-adress.";
18 2
            $domain = "Domänen är: " . gethostbyaddr($ipAdress);
19
        } else {
20 2
            $res = "Ip-adressen $ipAdress är inte giltig";
21
        }
22
23
        // returning the result to controller to send to view
24
        $data = [
25 2
            "res" => $res,
26 2
            "domain" => $domain ?? null
27
        ];
28
29 2
        return $data;
30
    }
31
}
32