Completed
Push — master ( 87f519...24448e )
by Ger
14s queued 11s
created

FreeGeoIp::hydrate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 14
rs 9.9
cc 1
nc 1
nop 2
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 = json_decode($this->executeRequest($this->url($ip)), true);
24
25
        if (null === $driverResponse) {
26
            throw new AddressNotFoundException("The IP address {$ip} could not be found.");
27
        }
28
29
        return new Response($driverResponse);
30
    }
31
}
32