GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 98364d...4f9955 )
by Eric
09:20 queued 03:56
created

ElevationService::buildCoordinate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Service\Elevation;
13
14
use Http\Client\HttpClient;
15
use Http\Message\MessageFactory;
16
use Ivory\GoogleMap\Base\Coordinate;
17
use Ivory\GoogleMap\Service\AbstractService;
18
use Ivory\GoogleMap\Service\Elevation\Request\ElevationRequestInterface;
19
use Ivory\GoogleMap\Service\Elevation\Response\ElevationResponse;
20
use Ivory\GoogleMap\Service\Elevation\Response\ElevationResult;
21
use Ivory\GoogleMap\Service\Utility\Parser;
22
23
/**
24
 * @author GeLo <[email protected]>
25
 */
26
class ElevationService extends AbstractService
27
{
28
    /**
29
     * @param HttpClient     $client
30
     * @param MessageFactory $messageFactory
31
     * @param Parser|null    $parser
32
     */
33
    public function __construct(HttpClient $client, MessageFactory $messageFactory, Parser $parser = null)
34
    {
35
        parent::__construct($client, $messageFactory, 'http://maps.googleapis.com/maps/api/elevation', $parser);
36
    }
37
38
    /**
39
     * @param ElevationRequestInterface $request
40
     *
41
     * @return ElevationResponse
42
     */
43 View Code Duplication
    public function process(ElevationRequestInterface $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $response = $this->getClient()->sendRequest($this->createRequest($request->build()));
46
        $data = $this->parse((string) $response->getBody());
47
48
        return $this->buildResponse($data);
49
    }
50
51
    /**
52
     * @param mixed[] $data
53
     *
54
     * @return ElevationResponse
55
     */
56 View Code Duplication
    private function buildResponse(array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        $response = new ElevationResponse();
59
        $response->setStatus($data['status']);
60
        $response->setResults($this->buildResults($data['results']));
61
62
        return $response;
63
    }
64
65
    /**
66
     * @param mixed[] $data
67
     *
68
     * @return ElevationResult[]
69
     */
70
    private function buildResults(array $data)
71
    {
72
        $results = [];
73
74
        foreach ($data as $result) {
75
            $results[] = $this->buildResult($result);
76
        }
77
78
        return $results;
79
    }
80
81
    /**
82
     * @param mixed[] $data
83
     *
84
     * @return ElevationResult
85
     */
86
    private function buildResult(array $data)
87
    {
88
        $element = new ElevationResult();
89
        $element->setLocation($this->buildCoordinate($data['location']));
90
        $element->setElevation($data['elevation']);
91
92
        if (isset($data['resolution'])) {
93
            $element->setResolution($data['resolution']);
94
        }
95
96
        return $element;
97
    }
98
99
    /**
100
     * @param mixed[] $data
101
     *
102
     * @return Coordinate
103
     */
104
    private function buildCoordinate(array $data)
105
    {
106
        return new Coordinate($data['lat'], $data['lng']);
107
    }
108
}
109