1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * Class IpValidator |
||||
5 | * Validate ip and return result. |
||||
6 | */ |
||||
7 | |||||
8 | namespace Anax\Models; |
||||
9 | |||||
10 | use Anax\Config\access; |
||||
0 ignored issues
–
show
|
|||||
11 | |||||
12 | class IpValidator |
||||
13 | { |
||||
14 | private $keys; |
||||
15 | |||||
16 | public function setKeys($config) |
||||
17 | { |
||||
18 | $this->keys = $config; |
||||
19 | } |
||||
20 | |||||
21 | /** |
||||
22 | * Curl from url |
||||
23 | */ |
||||
24 | public function curl($url) |
||||
25 | { |
||||
26 | $curl = curl_init($url); |
||||
27 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||||
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
![]() |
|||||
28 | $data = 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
![]() |
|||||
29 | curl_close($curl); |
||||
0 ignored issues
–
show
It seems like
$curl 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
![]() |
|||||
30 | |||||
31 | return $data; |
||||
32 | } |
||||
33 | |||||
34 | /** |
||||
35 | * Validate IP-adress |
||||
36 | */ |
||||
37 | public function validateIp($ipAdress) |
||||
38 | { |
||||
39 | $accessToken = $this->keys["ipValidator"]; |
||||
40 | $stackUrl = 'http://api.ipstack.com/' . $ipAdress . '?access_key=' . $accessToken . ''; |
||||
41 | |||||
42 | $host = ""; |
||||
43 | $stack = ""; |
||||
44 | $type = ""; |
||||
45 | $valid = ""; |
||||
46 | |||||
47 | if (filter_var($ipAdress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
||||
48 | $host = gethostbyaddr($ipAdress); |
||||
49 | $stack = json_decode($this->curl($stackUrl)); |
||||
50 | $type = "IPv4"; |
||||
51 | $valid = true; |
||||
52 | } elseif (filter_var($ipAdress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
||||
53 | $host = gethostbyaddr($ipAdress); |
||||
54 | $stack = json_decode($this->curl($stackUrl)); |
||||
55 | $type = "IPv6"; |
||||
56 | $valid = true; |
||||
57 | } else { |
||||
58 | $valid = false; |
||||
59 | } |
||||
60 | |||||
61 | $data = [ |
||||
62 | "ip" => $ipAdress, |
||||
63 | "valid" => $valid, |
||||
64 | "type" => $type, |
||||
65 | "host" => $host, |
||||
66 | "stack" => $stack |
||||
67 | ]; |
||||
68 | return $data; |
||||
69 | } |
||||
70 | |||||
71 | /** |
||||
72 | * Get current IP-adress |
||||
73 | */ |
||||
74 | public function getYourIp($request) |
||||
75 | { |
||||
76 | if (!empty($request->getServer('HTTP_CLIENT_IP'))) { |
||||
77 | $ipAdress = $server('HTTP_CLIENT_IP'); |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
78 | } elseif (!empty($request->getServer('HTTP_X_FORWARDED_FOR'))) { |
||||
79 | $ipAdress = $request->getServer('HTTP_X_FORWARDED_FOR'); |
||||
80 | } else { |
||||
81 | $ipAdress = $request->getServer('REMOTE_ADDR'); |
||||
82 | } |
||||
83 | |||||
84 | return $ipAdress; |
||||
85 | } |
||||
86 | } |
||||
87 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths