Total Complexity | 8 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
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) |
|
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() |
|
57 | } |
||
58 | |||
59 | 7 | public function getLat() |
|
60 | { |
||
61 | 7 | return $this->lat; |
|
62 | } |
||
63 | |||
64 | 7 | public function getLong() |
|
67 | } |
||
68 | } |
||
69 |