Conditions | 4 |
Paths | 6 |
Total Lines | 11 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | function get_client_ip() |
||
|
|||
29 | { |
||
30 | if (!empty($_SERVER['REMOTE_ADDR'])) { |
||
31 | $ip = $_SERVER['REMOTE_ADDR']; |
||
32 | } else { |
||
33 | // for php-cli(phpunit etc.) |
||
34 | $ip = defined('PHPUNIT_RUNNING') ? '127.0.0.1' : gethostbyname(gethostname()); |
||
35 | } |
||
36 | |||
37 | return filter_var($ip, FILTER_VALIDATE_IP) ?: '127.0.0.1'; |
||
38 | } |
||
39 | |||
58 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: