Ipstack::setLocation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 13
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\LocationProvider;
4
5
class Ipstack implements LocationProviderInterface
6
{
7
    private $apiKey;
8
    private $ip;
9
    private $type;
10
    private $city;
11
    private $country;
12
    private $long;
13
    private $lat;
14
    private $curl;
15
16 10
    public function __construct($curl, $cfg)
17
    {
18 10
        $this->curl = $curl;
19 10
        $keys = $cfg->load("locationprovider.php");
20 10
        $this->apiKey = $keys["config"]["apiKey"];
21 10
    }
22
23
24 8
    public function setLocation(string $ip)
25
    {
26 8
        $curl = $this->curl;
27 8
        $url = "http://api.ipstack.com/" . $ip . "?access_key=" . $this->apiKey;
28
29 8
        $res = $curl->get($url);
30
31 8
        $this->ip = $res->ip;
32 8
        $this->type = $res->type;
33 8
        $this->city = $res->city;
34 8
        $this->country = $res->country_name;
35 8
        $this->lat = $res->latitude;
36 8
        $this->long = $res->longitude;
37 8
    }
38
39 7
    public function getCity()
40
    {
41 7
        return $this->city;
42
    }
43
44 1
    public function getType()
45
    {
46 1
        return $this->type;
47
    }
48
49 7
    public function getCountry()
50
    {
51 7
        return $this->country;
52
    }
53
54 1
    public function getIp()
55
    {
56 1
        return $this->ip;
57
    }
58
59 7
    public function getLat()
60
    {
61 7
        return $this->lat;
62
    }
63
64 7
    public function getLong()
65
    {
66 7
        return $this->long;
67
    }
68
}
69