Completed
Push — master ( 0d83f4...f1be79 )
by Tobias
02:46
created

GeocodeEarth::executeQuery()   D

Complexity

Conditions 20
Paths 20

Size

Total Lines 67
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 20
eloc 45
c 1
b 0
f 1
nc 20
nop 1
dl 0
loc 67
rs 4.1666

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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