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
![]() |
|||||
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
|
|||||
61 | } else { |
||||
62 | 2 | $ipval = "IP is not a valid IP address"; |
|||
63 | 2 | return $ipval; |
|||
0 ignored issues
–
show
|
|||||
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
|
|||||
81 | 2 | } elseif (filter_var($ip, FILTER_VALIDATE_IP)) { |
|||
82 | 2 | $host = gethostbyaddr("$ip"); |
|||
83 | 2 | return $host; |
|||
0 ignored issues
–
show
|
|||||
84 | } else { |
||||
85 | 2 | $host = "No valid domain"; |
|||
86 | 2 | return $host; |
|||
0 ignored issues
–
show
|
|||||
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
![]() |
|||||
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
![]() |
|||||
104 | $decoded_result = json_decode($result); |
||||
105 | return $decoded_result; |
||||
106 | } |
||||
107 | } |
||||
108 |