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.

GeocodeQuery::getLimit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Query;
14
15
use Geocoder\Exception\InvalidArgument;
16
use Geocoder\Geocoder;
17
use Geocoder\Model\Bounds;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
final class GeocodeQuery implements Query
23
{
24
    /**
25
     * The address or text that should be geocoded.
26
     *
27
     * @var string
28
     */
29
    private $text;
30
31
    /**
32
     * @var Bounds|null
33
     */
34
    private $bounds;
35
36
    /**
37
     * @var string|null
38
     */
39
    private $locale;
40
41
    /**
42
     * @var int
43
     */
44
    private $limit = Geocoder::DEFAULT_RESULT_LIMIT;
45
46
    /**
47
     * @var array
48
     */
49
    private $data = [];
50
51
    /**
52
     * @param string $text
53
     */
54
    private function __construct(string $text)
55
    {
56
        if (empty($text)) {
57
            throw new InvalidArgument('Geocode query cannot be empty');
58
        }
59
60
        $this->text = $text;
61
    }
62
63
    /**
64
     * @param string $text
65
     *
66
     * @return GeocodeQuery
0 ignored issues
show
Documentation introduced by
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
67
     */
68
    public static function create(string $text): self
69
    {
70
        return new self($text);
71
    }
72
73
    /**
74
     * @param string $text
75
     *
76
     * @return GeocodeQuery
77
     */
78
    public function withText(string $text): self
79
    {
80
        $new = clone $this;
81
        $new->text = $text;
82
83
        return $new;
84
    }
85
86
    /**
87
     * @param Bounds $bounds
88
     *
89
     * @return GeocodeQuery
90
     */
91
    public function withBounds(Bounds $bounds): self
92
    {
93
        $new = clone $this;
94
        $new->bounds = $bounds;
95
96
        return $new;
97
    }
98
99
    /**
100
     * @param string $locale
101
     *
102
     * @return GeocodeQuery
103
     */
104
    public function withLocale(string $locale): self
105
    {
106
        $new = clone $this;
107
        $new->locale = $locale;
108
109
        return $new;
110
    }
111
112
    /**
113
     * @param int $limit
114
     *
115
     * @return GeocodeQuery
116
     */
117
    public function withLimit(int $limit): self
118
    {
119
        $new = clone $this;
120
        $new->limit = $limit;
121
122
        return $new;
123
    }
124
125
    /**
126
     * @param string $name
127
     * @param mixed  $value
128
     *
129
     * @return GeocodeQuery
130
     */
131
    public function withData(string $name, $value): self
132
    {
133
        $new = clone $this;
134
        $new->data[$name] = $value;
135
136
        return $new;
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function getText(): string
143
    {
144
        return $this->text;
145
    }
146
147
    /**
148
     * @return Bounds|null
149
     */
150
    public function getBounds()
151
    {
152
        return $this->bounds;
153
    }
154
155
    /**
156
     * @return string|null
157
     */
158
    public function getLocale()
159
    {
160
        return $this->locale;
161
    }
162
163
    /**
164
     * @return int
165
     */
166
    public function getLimit(): int
167
    {
168
        return $this->limit;
169
    }
170
171
    /**
172
     * @param string     $name
173
     * @param mixed|null $default
174
     *
175
     * @return mixed
176
     */
177
    public function getData(string $name, $default = null)
178
    {
179
        if (!array_key_exists($name, $this->data)) {
180
            return $default;
181
        }
182
183
        return $this->data[$name];
184
    }
185
186
    /**
187
     * @return array
188
     */
189
    public function getAllData(): array
190
    {
191
        return $this->data;
192
    }
193
194
    /**
195
     * String for logging. This is also a unique key for the query
196
     *
197
     * @return string
198
     */
199
    public function __toString()
200
    {
201
        return sprintf('GeocodeQuery: %s', json_encode([
202
            'text' => $this->getText(),
203
            'bounds' => $this->getBounds() ? $this->getBounds()->toArray() : 'null',
204
            'locale' => $this->getLocale(),
205
            'limit' => $this->getLimit(),
206
            'data' => $this->getAllData(),
207
        ]));
208
    }
209
}
210