1 | <?php |
||||
2 | |||||
3 | namespace Anax\Models; |
||||
4 | |||||
5 | class GetGeo |
||||
6 | { |
||||
7 | public function getGeo($ip) |
||||
8 | { |
||||
9 | global $di; |
||||
10 | |||||
11 | $config = $di->get("configuration")->load("apikey.php"); |
||||
12 | $access_key = $config["config"]["keyHolder"]["apiKey"]; |
||||
13 | |||||
14 | // Initialize CURL: |
||||
15 | $ch = curl_init('http://api.ipstack.com/'.$ip.'?access_key='.$access_key.''); |
||||
16 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
17 | |||||
18 | // Store the data: |
||||
19 | $json = curl_exec($ch); |
||||
0 ignored issues
–
show
It seems like
$ch can also be of type false ; however, parameter $ch of curl_exec() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
20 | curl_close($ch); |
||||
0 ignored issues
–
show
It seems like
$ch can also be of type false ; however, parameter $ch of curl_close() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
21 | |||||
22 | // Decode JSON response: |
||||
23 | $api_result = json_decode($json, true); |
||||
24 | |||||
25 | // Output the "capital" object inside "location" |
||||
26 | $data = [ |
||||
27 | "city" => $api_result['city'] ?? null, |
||||
28 | "country_name" => $api_result['country_name'] ?? null, |
||||
29 | "region_name" => $api_result['region_name'] ?? null, |
||||
30 | "longitude" => $api_result['longitude'] ?? null, |
||||
31 | "latitude" => $api_result['latitude'] ?? null |
||||
32 | ]; |
||||
33 | |||||
34 | return $data; |
||||
35 | } |
||||
36 | } |
||||
37 |