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 — place-services ( fedba7 )
by Eric
03:31
created

AbstractPlaceAutocompleteRequest::buildQuery()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
rs 8.6737
cc 5
eloc 11
nc 16
nop 0
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\Place\Autocomplete\Request;
13
14
use Ivory\GoogleMap\Base\Coordinate;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
abstract class AbstractPlaceAutocompleteRequest implements PlaceAutocompleteRequestInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    private $input;
25
26
    /**
27
     * @var int|null
28
     */
29
    private $offset;
30
31
    /**
32
     * @var Coordinate|null
33
     */
34
    private $location;
35
36
    /**
37
     * @var float|null
38
     */
39
    private $radius;
40
41
    /**
42
     * @var string|null
43
     */
44
    private $language;
45
46
    /**
47
     * @param string $input
48
     */
49
    public function __construct($input)
50
    {
51
        $this->setInput($input);
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getInput()
58
    {
59
        return $this->input;
60
    }
61
62
    /**
63
     * @param string $input
64
     */
65
    public function setInput($input)
66
    {
67
        $this->input = $input;
68
    }
69
70
    /**
71
     * @return bool
72
     */
73
    public function hasOffset()
74
    {
75
        return $this->offset !== null;
76
    }
77
78
    /**
79
     * @return int|null
80
     */
81
    public function getOffset()
82
    {
83
        return $this->offset;
84
    }
85
86
    /**
87
     * @param int|null $offset
88
     */
89
    public function setOffset($offset)
90
    {
91
        $this->offset = $offset;
92
    }
93
94
    /**
95
     * @return bool
96
     */
97
    public function hasLocation()
98
    {
99
        return $this->location !== null;
100
    }
101
102
    /**
103
     * @return Coordinate|null
104
     */
105
    public function getLocation()
106
    {
107
        return $this->location;
108
    }
109
110
    /**
111
     * @param Coordinate|null $location
112
     */
113
    public function setLocation(Coordinate $location = null)
114
    {
115
        $this->location = $location;
116
    }
117
118
    /**
119
     * @return bool
120
     */
121
    public function hasRadius()
122
    {
123
        return $this->radius !== null;
124
    }
125
126
    /**
127
     * @return float|null
128
     */
129
    public function getRadius()
130
    {
131
        return $this->radius;
132
    }
133
134
    /**
135
     * @param float|null $radius
136
     */
137
    public function setRadius($radius)
138
    {
139
        $this->radius = $radius;
140
    }
141
142
    /**
143
     * @return bool
144
     */
145
    public function hasLanguage()
146
    {
147
        return $this->language !== null;
148
    }
149
150
    /**
151
     * @return string|null
152
     */
153
    public function getLanguage()
154
    {
155
        return $this->language;
156
    }
157
158
    /**
159
     * @param string|null $language
160
     */
161
    public function setLanguage($language)
162
    {
163
        $this->language = $language;
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169
    public function buildQuery()
170
    {
171
        $query = ['input' => $this->input];
172
173
        if ($this->hasOffset()) {
174
            $query['offset'] = $this->offset;
175
        }
176
177
        if ($this->hasLocation()) {
178
            $query['location'] = $this->buildCoordinate($this->location);
0 ignored issues
show
Bug introduced by
It seems like $this->location can be null; however, buildCoordinate() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
179
        }
180
181
        if ($this->hasRadius()) {
182
            $query['radius'] = $this->radius;
183
        }
184
185
        if ($this->hasLanguage()) {
186
            $query['language'] = $this->language;
187
        }
188
189
        return $query;
190
    }
191
192
    /**
193
     * @param Coordinate $coordinate
194
     *
195
     * @return string
196
     */
197
    private function buildCoordinate(Coordinate $coordinate)
198
    {
199
        return $coordinate->getLatitude().','.$coordinate->getLongitude();
200
    }
201
}
202