Test Failed
Push — master ( df0f49...c2d884 )
by Christofer
02:26
created

Location   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getLocation() 0 28 2
1
<?php
2
3
namespace Chai17\Models;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Chai17\Models;
8
9
class Location implements ContainerInjectableInterface
10
{
11
12
    use ContainerInjectableTrait;
13
14
15
16
    public function getLocation($ipNumber)
17
    {
18
        $location = [];
19
        $api = $this->di->get("ipstack");
20
        $ipstack = $api["config"];
21
        $api = $this->di->get("mapquest");
22
        $mapquest = $api["config"];
23
        $validateIP = new Models\ValidateIP;
24
        $test = $validateIP->validate($ipNumber);
25
        if ($test[0]) {
26
            $location = $getJson->cUrl($ipstack["url"]. $ipNumber. '?access_key='. $ipstack["key"]);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $getJson seems to be never defined.
Loading history...
27
            $location = json_decode($location, true);
28
            $latitude = $location["latitude"];
29
            $longitude = $location["longitude"];
30
            $location = [$location["city"], $latitude, $longitude];
31
        } else {
32
            $search = array('å','ä','ö');
33
            $replace = array('a','a','o');
34
            $ipNumber = str_replace($search, $replace, $ipNumber);
35
            $location = $getJson->cUrl($mapquest["url"]. $mapquest["key"]. $mapquest["extra"]. $ipNumber);
36
            $location = json_decode($location, true);
37
            $latitude = $location["results"][0]["locations"][0]["latLng"]["lat"];
38
            $longitude = $location["results"][0]["locations"][0]["latLng"]["lng"];
39
            $city = $location["results"][0]["locations"][0]["adminArea5"] ?? "Ingen ort";
40
            $location = [$city, $latitude, $longitude];
41
        }
42
43
        return $location;
44
45
    }
46
47
}
48