FreeGeoIp   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A url() 0 3 1
A request() 0 15 3
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