Location   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 29
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getLocation() 0 26 2
1
<?php
2
3
namespace Chai17\Models;
4
5
class Location
6
{
7
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
    }
35
}
36