| Total Complexity | 10 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class GeoLocation |
||
| 8 | { |
||
| 9 | private $api; |
||
| 10 | private $curl = null; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * |
||
| 14 | * @return void |
||
| 15 | */ |
||
| 16 | 29 | public function __construct(object $curl) |
|
| 17 | { |
||
| 18 | 29 | $filePath = "/config/api_ipstack.php"; |
|
| 19 | 29 | $apiKey = "apiKey"; |
|
| 20 | 29 | $file = ANAX_INSTALL_PATH . $filePath; |
|
| 21 | 29 | $ipStack = file_exists($file) ? require $file : null; |
|
| 22 | 29 | $this->api = $ipStack ? $ipStack[$apiKey] : getenv("API_KEY"); |
|
| 23 | 29 | $this->curl = $curl; |
|
| 24 | 29 | } |
|
| 25 | |||
| 26 | /** |
||
| 27 | * Method to get user ip. |
||
| 28 | * |
||
| 29 | * @return string|void $ipAdr |
||
| 30 | */ |
||
| 31 | 12 | public function getUserIp() |
|
| 32 | { |
||
| 33 | 12 | $ipAdr = null; |
|
| 34 | |||
| 35 | 12 | if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 36 | 1 | $ipAdr = $_SERVER['HTTP_CLIENT_IP']; |
|
| 37 | 11 | } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 38 | 1 | $ipAdr = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 39 | 10 | } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
| 40 | 1 | $ipAdr = $_SERVER['REMOTE_ADDR']; |
|
| 41 | } else { |
||
| 42 | 9 | $ipAdr = "X.X.X.X"; |
|
| 43 | } |
||
| 44 | 12 | return $ipAdr; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Method to get location of a ip address. |
||
| 49 | * |
||
| 50 | * @return array|void $res |
||
| 51 | */ |
||
| 52 | 8 | public function getLocation( |
|
| 66 | } |
||
| 67 | } |
||
| 68 |