Ipstack   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 62
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getIp() 0 3 1
A getType() 0 3 1
A setLocation() 0 13 1
A getCountry() 0 3 1
A getLong() 0 3 1
A getLat() 0 3 1
A getCity() 0 3 1
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