1 | <?php |
||||
2 | |||||
3 | namespace Anax\Models; |
||||
4 | |||||
5 | class GeoApi extends IpValidator |
||||
6 | { |
||||
7 | /** |
||||
8 | * model class for finding coordinates matching the ip adress |
||||
9 | * using the geolocation api 'ipstack' |
||||
10 | * child class to IpValidator |
||||
11 | */ |
||||
12 | public function findGeoLocation($ipAdress) |
||||
13 | { |
||||
14 | global $di; |
||||
15 | |||||
16 | // get the secret api key |
||||
17 | $config = $di->get("configuration")->load("api_keys.php") ?? null; |
||||
18 | $apiKey = $config["config"]["ipStack"]["apiKey"] ?? null; |
||||
19 | |||||
20 | // make curl api call with ip address and api key |
||||
21 | $ch1 = curl_init('http://api.ipstack.com/'.$ipAdress.'?access_key='.$apiKey.''); |
||||
22 | curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
23 | $json = curl_exec($ch1); |
||||
0 ignored issues
–
show
It seems like
$ch1 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
![]() |
|||||
24 | curl_close($ch1); |
||||
0 ignored issues
–
show
It seems like
$ch1 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
![]() |
|||||
25 | |||||
26 | /** |
||||
27 | * decode the json result |
||||
28 | * for usage in both view and rest-api controller |
||||
29 | */ |
||||
30 | $result = json_decode($json, true); |
||||
31 | |||||
32 | $data = [ |
||||
33 | "city" => $result['city'] ?? "-", |
||||
34 | "country_name" => $result['country_name'] ?? "-", |
||||
35 | "longitude" => $result['longitude'] ?? "-", |
||||
36 | "latitude" => $result['latitude'] ?? "-" |
||||
37 | ]; |
||||
38 | |||||
39 | return $data; |
||||
40 | } |
||||
41 | } |
||||
42 |