1 | <?php |
||||
2 | namespace Lioo19\Models; |
||||
3 | |||||
4 | /** |
||||
5 | * Class for findning coordinates and place with ip |
||||
6 | * |
||||
7 | */ |
||||
8 | class IpGeo |
||||
9 | { |
||||
10 | /** |
||||
11 | * @var string $ipinput userinputted ip |
||||
12 | * @var string $curl curl-object |
||||
13 | */ |
||||
14 | public $ipinput; |
||||
15 | private $curl; |
||||
16 | |||||
17 | /** |
||||
18 | * Constructor to assign user input and address to use |
||||
19 | * |
||||
20 | * @param null|string $ipinp User input |
||||
21 | */ |
||||
22 | 1 | public function setInput(string $ipinp = "") |
|||
23 | { |
||||
24 | 1 | $this->ipinput = $ipinp; |
|||
25 | 1 | } |
|||
26 | |||||
27 | /** |
||||
28 | * Method for retriving the geo-coordinates for given ip-address |
||||
29 | * @return array With parts of valid JSON-repsonse |
||||
30 | */ |
||||
31 | public function fetchGeo($url = "http://api.ipstack.com/") |
||||
32 | { |
||||
33 | $this->curl = curl_init(); |
||||
34 | $apikey = require ANAX_INSTALL_PATH . "/config/apikeys.php"; |
||||
35 | $accesskey = $apikey["ipstack"]; |
||||
36 | //sets the url for curl to the correct one |
||||
37 | curl_setopt($this->curl, CURLOPT_URL, "$url" . $this->ipinput . "?access_key=" . $accesskey); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
38 | //returns a string |
||||
39 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); |
||||
40 | //execute the started curl-session |
||||
41 | $output = curl_exec($this->curl); |
||||
0 ignored issues
–
show
It seems like
$this->curl 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
![]() |
|||||
42 | $exploded = json_decode($output, true); |
||||
43 | $data = [ |
||||
44 | "country" => $exploded["country_name"], |
||||
45 | "city" => $exploded["city"], |
||||
46 | "latitude" => $exploded["latitude"], |
||||
47 | "longitude" => $exploded["longitude"], |
||||
48 | ]; |
||||
49 | //close curl-session to free up space |
||||
50 | curl_close($this->curl); |
||||
0 ignored issues
–
show
It seems like
$this->curl 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
![]() |
|||||
51 | |||||
52 | return $data; |
||||
53 | } |
||||
54 | } |
||||
55 |