Ip::get()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
1
<?php
2
3
namespace Ipify;
4
5
use \Requests;
6
use \Requests_Exception;
7
use Ipify\Exception\ConnectionError;
8
use Ipify\Exception\ServiceError;
9
10
class Ip {
11
12
    public static function get()
13
    {
14
15
        try {
16
            $response = Requests::get(Settings::$endpoint, array('User-Agent' => Settings::buildUserAgent()));
17
        } catch (Requests_Exception $e) {
18
            throw new ConnectionError("The request failed because it wasn't able to reach the ipify service.
19
                This is most likely due to a networking error of some sort.");
20
        }
21
22
        if ($response->status_code !== 200) {
23
            throw new ServiceError('Received an invalid status code from ipify:' . (string) $response->status_code .
24
                '. The service might be experiencing issues.');
25
        }
26
27
        return $response->body;
28
29
    }
30
31
}
32