GeocodeEarth::reverseQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 7
rs 10
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\GeocodeEarth;
14
15
use Geocoder\Collection;
16
use Geocoder\Exception\InvalidCredentials;
17
use Geocoder\Query\GeocodeQuery;
18
use Geocoder\Query\ReverseQuery;
19
use Geocoder\Provider\Pelias\Pelias;
20
use Geocoder\Provider\Provider;
21
use Http\Client\HttpClient;
22
23
final class GeocodeEarth extends Pelias implements Provider
24
{
25
    const API_URL = 'https://api.geocode.earth/';
26
27
    const API_VERSION = 1;
28
29
    /**
30
     * @var string
31
     */
32
    private $apiKey;
33
34
    /**
35
     * @param HttpClient $client an HTTP adapter
36
     * @param string     $apiKey an API key
37
     */
38
    public function __construct(HttpClient $client, string $apiKey)
39
    {
40
        if (empty($apiKey)) {
41
            throw new InvalidCredentials('No API key provided.');
42
        }
43
44
        $this->apiKey = $apiKey;
45
        parent::__construct($client, self::API_URL, self::API_VERSION);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function geocodeQuery(GeocodeQuery $query): Collection
52
    {
53
        $url = $this->getGeocodeQueryUrl($query, [
54
            'api_key' => $this->apiKey,
55
        ]);
56
57
        return $this->executeQuery($url);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function reverseQuery(ReverseQuery $query): Collection
64
    {
65
        $url = $this->getReverseQueryUrl($query, [
66
            'api_key' => $this->apiKey,
67
        ]);
68
69
        return $this->executeQuery($url);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getName(): string
76
    {
77
        return 'geocode_earth';
78
    }
79
}
80