Issues (21)

src/Ip2/IpStack.php (4 issues)

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
It seems like $cHan can also be of type false; however, parameter $ch of curl_setopt() 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 ignore-type  annotation

16
            curl_setopt(/** @scrutinizer ignore-type */ $cHan, CURLOPT_URL, "http://api.ipstack.com/{$ipAd}?access_key={$key}");
Loading history...
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 ignore-type  annotation

20
            $res = json_decode(curl_exec(/** @scrutinizer ignore-type */ $cHan), true);
Loading history...
21
22 2
            $data["ip"] = $res["ip"];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
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 ignore-type  annotation

29
            curl_close(/** @scrutinizer ignore-type */ $cHan);
Loading history...
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