Location::getLocation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 20
nc 2
nop 3
dl 0
loc 26
ccs 21
cts 21
cp 1
crap 2
rs 9.6
c 0
b 0
f 0
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