Passed
Push — master ( 24448e...4daf45 )
by Ger
04:03
created

GeoLocationDb   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A url() 0 3 1
A request() 0 9 2
1
<?php
2
3
namespace Psonrie\GeoLocation\Drivers;
4
5
use Psonrie\GeoLocation\Exceptions\AddressNotFoundException;
6
use Psonrie\GeoLocation\Response;
7
8
class GeoLocationDb extends Driver
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    protected function url($ip)
14
    {
15
        return "https://geolocation-db.com/jsonp/$ip";
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function request($ip)
22
    {
23
        $driverResponse = json_decode($this->executeRequest($this->url($ip)), true);
0 ignored issues
show
Bug introduced by
It seems like $this->executeRequest($this->url($ip)) can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $driverResponse = json_decode(/** @scrutinizer ignore-type */ $this->executeRequest($this->url($ip)), true);
Loading history...
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