| Conditions | 2 |
| Paths | 2 |
| Total Lines | 26 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | 2 | public function getLocation($ipNumber, $ipstack, $mapquest) |
|
| 9 | { |
||
| 10 | 2 | $validateIP = new ValidateIP; |
|
| 11 | 2 | $getJson = new Curl; |
|
| 12 | 2 | $test = $validateIP->validate($ipNumber); |
|
| 13 | |||
| 14 | 2 | if ($test[0]) { |
|
| 15 | 2 | $location = $getJson->cUrl($ipstack["url"]. $ipNumber. '?access_key='. $ipstack["key"]); |
|
| 16 | 2 | $location = json_decode($location, true); |
|
| 17 | 2 | $latitude = $location["latitude"]; |
|
| 18 | 2 | $longitude = $location["longitude"]; |
|
| 19 | 2 | $location = array("city"=> $location["city"], "latitude"=> $latitude, "longitude"=> $longitude); |
|
| 20 | 2 | return $location; |
|
| 21 | } |
||
| 22 | |||
| 23 | 2 | $search = array('å','ä','ö'); |
|
| 24 | 2 | $replace = array('a','a','o'); |
|
| 25 | 2 | $ipNumber = str_replace($search, $replace, $ipNumber); |
|
| 26 | 2 | $location = $getJson->cUrl($mapquest["url"]. $mapquest["key"]. $mapquest["extra"]. $ipNumber); |
|
| 27 | 2 | $location = json_decode($location, true); |
|
| 28 | 2 | $latitude = $location["results"][0]["locations"][0]["latLng"]["lat"]; |
|
| 29 | 2 | $longitude = $location["results"][0]["locations"][0]["latLng"]["lng"]; |
|
| 30 | 2 | $city = $location["results"][0]["locations"][0]["adminArea5"] ?? "Ingen ort"; |
|
| 31 | 2 | $location = array("city"=> $city, "latitude"=> $latitude, "longitude"=> $longitude); |
|
| 32 | |||
| 33 | 2 | return $location; |
|
| 34 | } |
||
| 36 |