Completed
Push — master ( fc04f3...75ff0f )
by Tobias
04:47
created

HostIp::reverseQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Provider\HostIp;
14
15
use Geocoder\Collection;
16
use Geocoder\Model\AddressCollection;
17
use function json_decode;
18
19
/**
20
 * @author William Durand <[email protected]>
21
 */
22
final class HostIp extends AbstractHostIp
23
{
24
    /**
25
     * @var string
26
     */
27
    const ENDPOINT_URL = 'http://api.hostip.info/get_json.php?ip=%s&position=true';
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 4
    public function getName(): string
33
    {
34 4
        return 'host_ip';
35
    }
36
37
    /**
38
     * @param string $url
39
     *
40
     * @return Collection
41
     */
42 7
    protected function executeQuery(string $url): AddressCollection
43
    {
44 7
        $content = $this->getUrlContents($url);
45 2
        $data = json_decode($content, true);
46
47 2
        if (!$data) {
48
            return new AddressCollection([]);
49
        }
50
51 2
        return $this->prepareAddressCollection($data);
52
    }
53
}
54