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.

AbstractPlaceAutocompleteRequest::buildQuery()   B
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 11
nc 16
nop 0
crap 5
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 208
    public function __construct($input)
50
    {
51 208
        $this->setInput($input);
52 208
    }
53
54
    /**
55
     * @return string
56
     */
57 16
    public function getInput()
58
    {
59 16
        return $this->input;
60
    }
61
62
    /**
63
     * @param string $input
64
     */
65 208
    public function setInput($input)
66
    {
67 208
        $this->input = $input;
68 208
    }
69
70
    /**
71
     * @return bool
72
     */
73 148
    public function hasOffset()
74
    {
75 148
        return $this->offset !== null;
76
    }
77
78
    /**
79
     * @return int|null
80
     */
81 16
    public function getOffset()
82
    {
83 16
        return $this->offset;
84
    }
85
86
    /**
87
     * @param int|null $offset
88
     */
89 24
    public function setOffset($offset)
90
    {
91 24
        $this->offset = $offset;
92 24
    }
93
94
    /**
95
     * @return bool
96
     */
97 148
    public function hasLocation()
98
    {
99 148
        return $this->location !== null;
100
    }
101
102
    /**
103
     * @return Coordinate|null
104
     */
105 16
    public function getLocation()
106
    {
107 16
        return $this->location;
108
    }
109
110
    /**
111
     * @param Coordinate|null $location
112
     */
113 40
    public function setLocation(Coordinate $location = null)
114
    {
115 40
        $this->location = $location;
116 40
    }
117
118
    /**
119
     * @return bool
120
     */
121 148
    public function hasRadius()
122
    {
123 148
        return $this->radius !== null;
124
    }
125
126
    /**
127
     * @return float|null
128
     */
129 16
    public function getRadius()
130
    {
131 16
        return $this->radius;
132
    }
133
134
    /**
135
     * @param float|null $radius
136
     */
137 24
    public function setRadius($radius)
138
    {
139 24
        $this->radius = $radius;
140 24
    }
141
142
    /**
143
     * @return bool
144
     */
145 148
    public function hasLanguage()
146
    {
147 148
        return $this->language !== null;
148
    }
149
150
    /**
151
     * @return string|null
152
     */
153 16
    public function getLanguage()
154
    {
155 16
        return $this->language;
156
    }
157
158
    /**
159
     * @param string|null $language
160
     */
161 24
    public function setLanguage($language)
162
    {
163 24
        $this->language = $language;
164 24
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169 132
    public function buildQuery()
170
    {
171 132
        $query = ['input' => $this->input];
172
173 132
        if ($this->hasOffset()) {
174 20
            $query['offset'] = $this->offset;
175 10
        }
176
177 132
        if ($this->hasLocation()) {
178 36
            $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 18
        }
180
181 132
        if ($this->hasRadius()) {
182 20
            $query['radius'] = $this->radius;
183 10
        }
184
185 132
        if ($this->hasLanguage()) {
186 20
            $query['language'] = $this->language;
187 10
        }
188
189 132
        return $query;
190
    }
191
192
    /**
193
     * @param Coordinate $coordinate
194
     *
195
     * @return string
196
     */
197 36
    private function buildCoordinate(Coordinate $coordinate)
198
    {
199 36
        return $coordinate->getLatitude().','.$coordinate->getLongitude();
200
    }
201
}
202