| Conditions | 5 |
| Paths | 6 |
| Total Lines | 27 |
| 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 | 2 | if ($res["type"] == null) { |
|
| 48 | $json = [ |
||
| 49 | 1 | "Message" => "IP-adressen är fel. Försök igen!" |
|
| 50 | ]; |
||
| 51 | 1 | return $json; |
|
| 52 | } |
||
| 53 | $json = [ |
||
| 54 | 2 | "Type" => $res["type"], |
|
| 55 | 2 | "Valid" => $res["type"] ? "ipv4" || "ipv6" : "not valid", |
|
| 56 | 2 | "UserInput" => $res["ip"], |
|
| 57 | 2 | "Latitude" => $res["latitude"], |
|
| 58 | 2 | "Longitude" => $res["longitude"], |
|
| 59 | 2 | "City" => $res["city"], |
|
| 60 | 2 | "Country" => $res["country_name"], |
|
| 61 | ]; |
||
| 62 | 2 | return [$json]; |
|
| 63 | } |
||
| 64 | else { |
||
| 65 | $json = [ |
||
| 66 | "Message" => "IP-adressen är tom. Försök igen" |
||
| 67 | ]; |
||
| 68 | return $json; |
||
| 69 | } |
||
| 72 |