1 | <?php namespace Arcanedev\GeoIP\Drivers; |
||
14 | class IpApiDriver extends AbstractDriver |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Properties |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | /** |
||
21 | * Http client instance. |
||
22 | * |
||
23 | * @var \GuzzleHttp\Client |
||
24 | */ |
||
25 | protected $client; |
||
26 | |||
27 | /** |
||
28 | * An array of continents. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $continents = []; |
||
33 | |||
34 | /* ------------------------------------------------------------------------------------------------ |
||
35 | | Main Functions |
||
36 | | ------------------------------------------------------------------------------------------------ |
||
37 | */ |
||
38 | /** |
||
39 | * Init the driver. |
||
40 | */ |
||
41 | 18 | protected function init() |
|
52 | |||
53 | /** |
||
54 | * Locate the ip address. |
||
55 | * |
||
56 | * @param string $ipAddress |
||
57 | * |
||
58 | * @return \Arcanedev\GeoIP\Location |
||
59 | * |
||
60 | * @throws \Exception |
||
61 | */ |
||
62 | 6 | public function locate($ipAddress) |
|
63 | { |
||
64 | 6 | $response = $this->client->get("json/$ipAddress"); |
|
65 | |||
66 | // Parse body content |
||
67 | 6 | $data = json_decode($response->getBody()); |
|
68 | |||
69 | // Verify response status |
||
70 | 6 | if ($data->status !== 'success') { |
|
71 | throw new Exception("Request failed ({$data->message})"); |
||
72 | } |
||
73 | |||
74 | 6 | return $this->hydrate([ |
|
75 | 6 | 'ip' => $ipAddress, |
|
76 | 6 | 'iso_code' => $data->countryCode, |
|
77 | 6 | 'country' => $data->country, |
|
78 | 6 | 'city' => $data->city, |
|
79 | 6 | 'state' => $data->regionName, |
|
80 | 6 | 'state_code' => $data->region, |
|
81 | 6 | 'postal_code' => $data->zip, |
|
82 | 6 | 'latitude' => $data->lat, |
|
83 | 6 | 'longitude' => $data->lon, |
|
84 | 6 | 'timezone' => $data->timezone, |
|
85 | 6 | 'continent' => $this->getContinent($data->countryCode), |
|
86 | 3 | ]); |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * Update function for service. |
||
91 | * |
||
92 | * @return string |
||
93 | * |
||
94 | * @throws \Exception |
||
95 | */ |
||
96 | public function update() |
||
103 | |||
104 | /** |
||
105 | * Get continent based on country code. |
||
106 | * |
||
107 | * @param string $code |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 6 | private function getContinent($code) |
|
115 | |||
116 | /** |
||
117 | * Get the http client config. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | 18 | private function getHttpClientConfig() |
|
141 | |||
142 | /** |
||
143 | * Check if secure url. |
||
144 | * |
||
145 | * @return bool |
||
146 | */ |
||
147 | private function isSecure() |
||
151 | } |
||
152 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..