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

HostIp   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 32
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A executeQuery() 0 11 2
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