Conditions | 4 |
Paths | 6 |
Total Lines | 48 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 4.0245 |
Changes | 0 |
1 | <?php |
||
28 | 1 | public function getIp($ip) : array |
|
29 | { |
||
30 | 1 | if (filter_var($ip, FILTER_VALIDATE_IP)) { |
|
31 | 1 | $valid = "true"; |
|
32 | } else { |
||
33 | $valid = "false"; |
||
34 | } |
||
35 | |||
36 | 1 | if ($valid == "true") { |
|
37 | 1 | if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
38 | 1 | $ipv = "Ipv4"; |
|
39 | } else { |
||
40 | $ipv = "Ipv6"; |
||
41 | } |
||
42 | |||
43 | 1 | $key = $this->config->config; |
|
|
|||
44 | 1 | $details = json_decode(file_get_contents("http://api.ipstack.com/{$ip}?access_key={$key}")); |
|
45 | |||
46 | 1 | $domain = gethostbyaddr($ip); |
|
47 | 1 | $lat = $details->latitude; |
|
48 | 1 | $long = $details->longitude; |
|
49 | 1 | $country = $details->country_name; |
|
50 | 1 | $region = $details->region_name; |
|
51 | 1 | $city = $details->city; |
|
52 | |||
53 | return [ |
||
54 | 1 | "valid" => $valid, |
|
55 | 1 | "ip" => $ip, |
|
56 | 1 | "ipv" => $ipv, |
|
57 | 1 | "domain" => $domain, |
|
58 | 1 | "lat" => $lat, |
|
59 | 1 | "long" => $long, |
|
60 | 1 | "country" => $country, |
|
61 | 1 | "region" => $region, |
|
62 | 1 | "city" => $city |
|
63 | ]; |
||
64 | |||
65 | } else { |
||
66 | return [ |
||
67 | "valid" => "Not Valid IP", |
||
68 | "ip" => null, |
||
69 | "ipv" => null, |
||
70 | "domain" => null, |
||
71 | "lat" => null, |
||
72 | "long" => null, |
||
73 | "country" => null, |
||
74 | "region" => null, |
||
75 | "city" => null |
||
76 | ]; |
||
80 |