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

TimeZoneService::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
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\TimeZone;
13
14
use Http\Client\HttpClient;
15
use Http\Message\MessageFactory;
16
use Ivory\GoogleMap\Service\AbstractService;
17
use Ivory\GoogleMap\Service\TimeZone\Request\TimeZoneRequestInterface;
18
use Ivory\GoogleMap\Service\TimeZone\Response\TimeZoneResponse;
19
20
/**
21
 * @author GeLo <[email protected]>
22
 */
23
class TimeZoneService extends AbstractService
24
{
25
    /**
26
     * @param HttpClient     $client
27
     * @param MessageFactory $messageFactory
28
     */
29
    public function __construct(HttpClient $client, MessageFactory $messageFactory)
30
    {
31
        parent::__construct($client, $messageFactory, 'http://maps.googleapis.com/maps/api/timezone');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function setHttps($https)
38
    {
39
        if (!$https) {
40
            throw new \InvalidArgumentException('The http scheme is not supported.');
41
        }
42
43
        parent::setHttps($https);
44
    }
45
46
    /**
47
     * @param TimeZoneRequestInterface $request
48
     *
49
     * @return TimeZoneResponse
50
     */
51 View Code Duplication
    public function process(TimeZoneRequestInterface $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...
52
    {
53
        $response = $this->getClient()->sendRequest($this->createRequest($request->build()));
54
        $data = $this->parse((string) $response->getBody());
55
56
        return $this->buildResponse($data);
57
    }
58
59
    /**
60
     * @param string $data
61
     *
62
     * @return mixed[]
63
     */
64 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...
65
    {
66
        if ($this->getFormat() === self::FORMAT_JSON) {
67
            return json_decode($data, true);
68
        }
69
70
        return $this->getXmlParser()->parse($data, [], true);
71
    }
72
73
    /**
74
     * @param mixed[] $data
75
     *
76
     * @return TimeZoneResponse
77
     */
78
    private function buildResponse(array $data)
79
    {
80
        $response = new TimeZoneResponse();
81
        $response->setStatus($data['status']);
82
        $response->setDstOffset((int) $data['dstOffset']);
83
        $response->setRawOffset((int) $data['rawOffset']);
84
        $response->setTimeZoneId($data['timeZoneId']);
85
        $response->setTimeZoneName($data['timeZoneName']);
86
87
        return $response;
88
    }
89
}
90