| Conditions | 5 |
| Paths | 5 |
| Total Lines | 14 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 83 | public function ip() |
||
| 84 | { |
||
| 85 | static $ipFrom = ['HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR']; |
||
| 86 | foreach ($ipFrom as $key) { |
||
| 87 | if (array_key_exists($key, $_SERVER)) { |
||
| 88 | foreach (explode(',', $_SERVER[$key]) as $ip) { |
||
| 89 | $ip = trim($ip); |
||
| 90 | if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) { |
||
| 91 | return $ip; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | return '127.0.0.1'; |
||
| 97 | } |
||
| 106 | } |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: