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

GeoLocationDb::url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
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 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