Conditions | 5 |
Paths | 6 |
Total Lines | 28 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 5.0406 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
42 | 2 | public function curlIpApi($ipAdr): array |
|
43 | { |
||
44 | 2 | $curl = new CurlService(); |
|
45 | 2 | if ($ipAdr!= "") { |
|
46 | 2 | $res = $curl->getDataThroughCurl($this->getUrl() . $ipAdr . "?access_key=" . $this->getKey()); |
|
47 | |||
48 | 2 | if ($res["type"] == null) { |
|
49 | $json = [ |
||
50 | 1 | "Message" => "IP-adressen är fel. Försök igen!" |
|
51 | ]; |
||
52 | 1 | return $json; |
|
53 | } |
||
54 | $json = [ |
||
55 | 2 | "Type" => $res["type"], |
|
56 | 2 | "Valid" => $res["type"] ? "ipv4" || "ipv6" : "not valid", |
|
57 | 2 | "UserInput" => $res["ip"], |
|
58 | 2 | "Latitude" => $res["latitude"], |
|
59 | 2 | "Longitude" => $res["longitude"], |
|
60 | 2 | "City" => $res["city"], |
|
61 | 2 | "Country" => $res["country_name"], |
|
62 | ]; |
||
63 | 2 | return [$json]; |
|
64 | } |
||
65 | else { |
||
66 | $json = [ |
||
67 | "Message" => "IP-adressen är tom. Försök igen" |
||
68 | ]; |
||
69 | return $json; |
||
70 | } |
||
73 |