FreeGeoIp::request()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 3
nc 4
nop 1
1
<?php
2
3
namespace Psonrie\GeoLocation\Drivers;
4
5
use Psonrie\GeoLocation\Exceptions\AddressNotFoundException;
6
use Psonrie\GeoLocation\Response;
7
8
class FreeGeoIp extends Driver
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    protected function url($ip)
14
    {
15
        return "https://freegeoip.app/json/$ip";
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function request($ip)
22
    {
23
        $driverResponse = null;
24
25
        $content = $this->executeRequest($this->url($ip));
26
27
        if (is_string($content)) {
28
            $driverResponse = json_decode($content, true);
29
        }
30
31
        if (null === $driverResponse) {
32
            throw new AddressNotFoundException("The IP address {$ip} could not be found.");
33
        }
34
35
        return new Response($driverResponse);
36
    }
37
}
38