Issues (63)

src/Validate/Validate.php (8 issues)

1
<?php
2
3
namespace Aiur\Validate;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
/**
9
 * To ease rendering a page consisting of several views.
10
 */
11
class Validate implements ContainerInjectableInterface
12
{
13
    use ContainerInjectableTrait;
14
15
    private $url;
16
    private $apikey;
17
18
19
20
    /**
21
     * Set the view to be used for the layout.
22
     *
23
     * @param array $view configuration to create up the view.
24
     *
25
     * @return $this
26
     */
27 2
    public function setUrl($urlen)
28
    {
29 2
        $this->url = $urlen;
30 2
    }
31
32
33
    /**
34
     * Set the view to be used for the layout.
35
     *
36
     * @param array $view configuration to create up the view.
37
     *
38
     * @return $this
39
     */
40 2
    public function setKey($keyz)
41
    {
42 2
        $this->apikey = $keyz;
43 2
    }
44
45
46
    /**
47
     * Set the view to be used for the layout.
48
     *
49
     * @param array $view configuration to create up the view.
50
     *
51
     * @return $this
52
     */
53 2
    public function validateIp($ip)
54
    {
55 2
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
56 2
            $ipval = "IP is a valid IPv6 address";
57 2
            return $ipval;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ipval returns the type string which is incompatible with the documented return type Aiur\Validate\Validate.
Loading history...
58 2
        } elseif (filter_var($ip, FILTER_VALIDATE_IP)) {
59 2
            $ipval = "IP is a valid IPv4 address";
60 2
            return $ipval;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ipval returns the type string which is incompatible with the documented return type Aiur\Validate\Validate.
Loading history...
61
        } else {
62 2
            $ipval = "IP is not a valid IP address";
63 2
            return $ipval;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ipval returns the type string which is incompatible with the documented return type Aiur\Validate\Validate.
Loading history...
64
        }
65
    }
66
67
68
69
    /**
70
     * Set the view to be used for the layout.
71
     *
72
     * @param array $view configuration to create up the view.
73
     *
74
     * @return $this
75
     */
76 2
    public function getDomain($ip)
77
    {
78 2
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
79 2
            $host = gethostbyaddr("$ip");
80 2
            return $host;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $host returns the type string which is incompatible with the documented return type Aiur\Validate\Validate.
Loading history...
81 2
        } elseif (filter_var($ip, FILTER_VALIDATE_IP)) {
82 2
            $host = gethostbyaddr("$ip");
83 2
            return $host;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $host returns the type string which is incompatible with the documented return type Aiur\Validate\Validate.
Loading history...
84
        } else {
85 2
            $host = "No valid domain";
86 2
            return $host;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $host returns the type string which is incompatible with the documented return type Aiur\Validate\Validate.
Loading history...
87
        }
88
    }
89
90
91
    /**
92
     * Set the view to be used for the layout.
93
     *
94
     * @param array $view configuration to create up the view.
95
     *
96
     * @return $this
97
     */
98
    public function getCurl($ip)
99
    {
100
        $curl = curl_init();
101
        curl_setopt($curl, CURLOPT_URL, "{$this->url}/{$ip}?access_key={$this->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

101
        curl_setopt(/** @scrutinizer ignore-type */ $curl, CURLOPT_URL, "{$this->url}/{$ip}?access_key={$this->apikey}");
Loading history...
102
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
103
        $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

103
        $result = curl_exec(/** @scrutinizer ignore-type */ $curl);
Loading history...
104
        $decoded_result = json_decode($result);
105
        return $decoded_result;
106
    }
107
}
108