Issues (14)

src/Models/IpValidate.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Anax\Models;
4
5
use Anax\Config\apiTokens;
0 ignored issues
show
The type Anax\Config\apiTokens was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class IpValidate
8
{
9
    private $keys;
10
11 26
    public function setKeys($keyData)
12
    {
13 26
        $this->keys = $keyData;
14 26
    }
15
16 22
    public function validate($ips)
17
    {
18 22
        $valid = "";
19 22
        $domain = "";
20 22
        $status = "";
21 22
        $ipStackData = "";
22 22
        $accessKey = $this->keys['ipstack'];
23
24 22
        if (filter_var($ips, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
25 6
            $status = $ips . " är en giltig ipv4 adress.";
26 6
            $valid = true;
27 6
            $domain = gethostbyaddr($ips);
28 6
            $ipStackUrl = 'http://api.ipstack.com/' . $ips . '?access_key=' . $accessKey . '';
29 6
            $curlObj = new Curl;
30 6
            $ipStackData = json_decode($curlObj->curl($ipStackUrl));
31 16
        } else if (filter_var($ips, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
32 6
            $status = $ips . " är en giltig ipv6 adress.";
33 6
            $valid = true;
34 6
            $domain = gethostbyaddr($ips);
35 6
            $ipStackUrl = 'http://api.ipstack.com/' . $ips . '?access_key=' . $accessKey . '';
36 6
            $curlObj = new Curl;
37 6
            $ipStackData = json_decode($curlObj->curl($ipStackUrl));
38
        } else {
39 10
            $valid = false;
40 10
            $status = $ips . " är en ogiltig ip adress.";
41
        }
42
43
        $json = [
44 22
            "ip" => $ips,
45 22
            "domain" => $domain,
46 22
            "valid" => $valid,
47 22
            "status" => $status,
48 22
            "ipStackData" => $ipStackData,
49
        ];
50
51 22
        return $json;
52
    }
53
}
54