Ip   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 22
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 18 3
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