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 ( bcefff...98364d )
by Eric
03:01
created

ElevationService   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 23.96 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
c 1
b 0
f 1
lcom 1
cbo 8
dl 23
loc 96
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 7 7 1
A parse() 8 8 2
A buildResponse() 8 8 1
A buildResults() 0 10 2
A buildResult() 0 12 2
A buildCoordinate() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
22
/**
23
 * @author GeLo <[email protected]>
24
 */
25
class ElevationService extends AbstractService
26
{
27
    /**
28
     * @param HttpClient     $client
29
     * @param MessageFactory $messageFactory
30
     */
31
    public function __construct(HttpClient $client, MessageFactory $messageFactory)
32
    {
33
        parent::__construct($client, $messageFactory, 'http://maps.googleapis.com/maps/api/elevation');
34
    }
35
36
    /**
37
     * @param ElevationRequestInterface $request
38
     *
39
     * @return ElevationResponse
40
     */
41 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...
42
    {
43
        $response = $this->getClient()->sendRequest($this->createRequest($request->build()));
44
        $data = $this->parse((string) $response->getBody());
45
46
        return $this->buildResponse($data);
47
    }
48
49
    /**
50
     * @param string $data
51
     *
52
     * @return mixed[]
53
     */
54 View Code Duplication
    private function parse($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...
55
    {
56
        if ($this->getFormat() === self::FORMAT_JSON) {
57
            return json_decode($data, true);
58
        }
59
60
        return $this->getXmlParser()->parse($data);
61
    }
62
63
    /**
64
     * @param mixed[] $data
65
     *
66
     * @return ElevationResponse
67
     */
68 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...
69
    {
70
        $response = new ElevationResponse();
71
        $response->setStatus($data['status']);
72
        $response->setResults($this->buildResults($data['results']));
73
74
        return $response;
75
    }
76
77
    /**
78
     * @param mixed[] $data
79
     *
80
     * @return ElevationResult[]
81
     */
82
    private function buildResults(array $data)
83
    {
84
        $results = [];
85
86
        foreach ($data as $result) {
87
            $results[] = $this->buildResult($result);
88
        }
89
90
        return $results;
91
    }
92
93
    /**
94
     * @param mixed[] $data
95
     *
96
     * @return ElevationResult
97
     */
98
    private function buildResult(array $data)
99
    {
100
        $element = new ElevationResult();
101
        $element->setLocation($this->buildCoordinate($data['location']));
102
        $element->setElevation($data['elevation']);
103
104
        if (isset($data['resolution'])) {
105
            $element->setResolution($data['resolution']);
106
        }
107
108
        return $element;
109
    }
110
111
    /**
112
     * @param mixed[] $data
113
     *
114
     * @return Coordinate
115
     */
116
    private function buildCoordinate(array $data)
117
    {
118
        return new Coordinate($data['lat'], $data['lng']);
119
    }
120
}
121