Conditions | 4 |
Paths | 6 |
Total Lines | 33 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 4.0027 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | 6 | public function toJson($ip) : array |
|
12 | { |
||
13 | 6 | if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
14 | 2 | $ipv = "Ipv4"; |
|
15 | 4 | } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
16 | $ipv = "Ipv6"; |
||
17 | } else { |
||
18 | 4 | $ipv = null; |
|
19 | } |
||
20 | |||
21 | 6 | if ($ipv != null) { |
|
|
|||
22 | 2 | $details = json_decode(file_get_contents("http://api.ipstack.com/{$ip}?access_key=9e9f05f2e74673444b90a999a579ab3f")); |
|
23 | 2 | $domain = gethostbyaddr($ip); |
|
24 | return [ |
||
25 | 2 | "valid" => "valid IP", |
|
26 | 2 | "ip" => $ip, |
|
27 | 2 | "ipv" => $ipv, |
|
28 | 2 | "domain" => $domain, |
|
29 | 2 | "lat" => $details->latitude, |
|
30 | 2 | "lon" => $details->longitude, |
|
31 | 2 | "country" => $details->country_name, |
|
32 | 2 | "city" => $details->city |
|
33 | ]; |
||
34 | } else { |
||
35 | return [ |
||
36 | 4 | "valid" => "Not Valid IP", |
|
37 | "ip" => null, |
||
38 | "ipv" => null, |
||
39 | "domain" => null, |
||
40 | "lat" => null, |
||
41 | "lon" => null, |
||
42 | "country" => null, |
||
43 | "city" => null |
||
44 | ]; |
||
49 |