1 | <?php |
||||
2 | |||||
3 | namespace Anax\Ip2; |
||||
4 | |||||
5 | class IpStack |
||||
6 | { |
||||
7 | 4 | public function getInfo($ipAd) |
|||
8 | { |
||||
9 | 4 | $ipVal = new IpValidate(); |
|||
10 | |||||
11 | 4 | if ($ipVal->validate($ipAd)) { |
|||
12 | 2 | $key = "299a8efa45108d9ed496c061839b0232"; |
|||
13 | |||||
14 | 2 | $cHan = curl_init(); |
|||
15 | |||||
16 | 2 | curl_setopt($cHan, CURLOPT_URL, "http://api.ipstack.com/{$ipAd}?access_key={$key}"); |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
17 | 2 | curl_setopt($cHan, CURLOPT_RETURNTRANSFER, true); |
|||
18 | 2 | curl_setopt($cHan, CURLOPT_HEADER, false); |
|||
19 | |||||
20 | 2 | $res = json_decode(curl_exec($cHan), true); |
|||
0 ignored issues
–
show
It seems like
$cHan 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
![]() |
|||||
21 | |||||
22 | 2 | $data["ip"] = $res["ip"]; |
|||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
23 | 2 | $data["type"] = $res["type"]; |
|||
24 | 2 | $data["country"] = $res["country_name"]; |
|||
25 | 2 | $data["city"] = $res["city"]; |
|||
26 | 2 | $data["lat"] = $res["latitude"]; |
|||
27 | 2 | $data["long"] = $res["longitude"]; |
|||
28 | |||||
29 | 2 | curl_close($cHan); |
|||
0 ignored issues
–
show
It seems like
$cHan 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
![]() |
|||||
30 | } else { |
||||
31 | 2 | $data["ip"] = $ipAd; |
|||
32 | 2 | $data["type"] = "Ogiltig"; |
|||
33 | 2 | $data["country"] = "Inget"; |
|||
34 | 2 | $data["city"] = "Ingen"; |
|||
35 | 2 | $data["lat"] = ""; |
|||
36 | 2 | $data["long"] = ""; |
|||
37 | } |
||||
38 | 4 | return $data; |
|||
39 | } |
||||
40 | } |
||||
41 |