Issues (32)

src/Ip/IPChecker.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * Ip Checker, a class supporting IP validation.
4
 */
5
6
namespace Anax\Ip;
7
8
use Anax\Commons\ContainerInjectableInterface;
9
use Anax\Commons\ContainerInjectableTrait;
10
11
class IPChecker
12
{
13
14
    use ContainerInjectableTrait;
15
16 2
    public function checkIpv($ipv)
17
    {
18 2
        if (filter_var($ipv, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
19
            $hostname = gethostbyaddr($ipv);
20
            return "$ipv is a valid IPv6 address and the host is: $hostname";
21 2
        } elseif (filter_var($ipv, FILTER_VALIDATE_IP)) {
22 2
            $hostname = gethostbyaddr($ipv);
23 2
            return "$ipv is a valid IPv4 address and the host is: $hostname";
24
        } else {
25
            return "$ipv is not a valid IP address";
26
        }
27
    }
28
29 2
    public function geoTag($ipv)
30
    {
31 2
        $apiKey = require ANAX_INSTALL_PATH . "/config/apikey.php";
32 2
        $apiKey = $apiKey["geotag"];
33 2
        $curl = curl_init();
34
35 2
        curl_setopt($curl, CURLOPT_URL, "http://api.ipstack.com/$ipv?access_key=$apiKey");
0 ignored issues
show
It seems like $curl 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

35
        curl_setopt(/** @scrutinizer ignore-type */ $curl, CURLOPT_URL, "http://api.ipstack.com/$ipv?access_key=$apiKey");
Loading history...
36 2
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
37
38 2
        $result = curl_exec($curl);
0 ignored issues
show
It seems like $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 ignore-type  annotation

38
        $result = curl_exec(/** @scrutinizer ignore-type */ $curl);
Loading history...
39
40 2
        $decode = json_decode($result);
41
42 2
        return $decode;
43
    }
44
45 1
    public function verifyGeo($latitude, $longitude)
46
    {
47 1
        $validLat = preg_match('/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/', $latitude);
48 1
        $validLon = preg_match('/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/', $longitude);
49
50 1
        if (!$validLat && !$validLon) {
51
            return false;
52
        } else {
53 1
            return true;
54
        }
55
    }
56
}
57