IpVerifierMock   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getJson() 0 19 5
1
<?php
2
3
namespace Linder\Mock;
4
5
class IpVerifierMock
6
{
7
    /**
8
     * This method takes one argument:
9
     * A string that we are going to check if its a valid ip-adress.
10
     * Returning an json with some information.
11
     *
12
     * @param string $value
13
     *
14
     * @return array
15
     */
16 3
    public function getJson($ip) : array
17
    {
18 3
        $valid = filter_var($ip, FILTER_VALIDATE_IP) ? "true" : "false";
19 3
        if ($valid == "true") {
20 3
            $protocol = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? "ipv4" : "ipv6";
21 3
            $getHost = gethostbyaddr($ip);
22 3
            $domain = ($getHost == $ip) ? null : $getHost;
23
        } else {
24 2
            $protocol = null;
25 2
            $domain = null;
26
        }
27
        return [
28 3
            "ip" => $ip,
29 3
            "type" => $protocol,
30 3
            "domain" => $domain,
31 3
            "latitude" => 57.70887,
32 3
            "longitude" => 11.97456,
33
            "country_name" => null,
34
            "city" => null
35
        ];
36
    }
37
}
38