Skip to content

Commit 09d7eef

Browse files
authored
Enable PHPStan Level 6 (#1194)
* Update phpstan.neon * Update YandexTest.php * Update TomTomTest.php * Update PickPointTest.php * Update PickPoint.php * Update PhotonTest.php * Update PeliasTest.php * Update OpenRouteServiceTest.php * Update OpenCageTest.php * Update OpenCage.php * Update NominatimTest.php * Update MaxMindBinaryTest.php * Update MaxMindTest.php * [WIP] Apply PHPStan fixes * Apply PHPCSFixer fixes * [WIP] Apply PHPStan fixes * [WIP] Apply PHPStan fixes * Revert "[WIP] Apply PHPStan fixes" This reverts commit 734c5c52fbcba4bc12cbda07b58d902a79d47891. * [WIP] Apply PHPStan fixes * [WIP] Apply PHPStan fixes * Update phpstan-baseline.neon
1 parent 23bbe63 commit 09d7eef

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

Here.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ final class Here extends AbstractHttpProvider implements Provider
7373
public const REVERSE_CIT_ENDPOINT_URL_APP_CODE = 'https://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.json';
7474

7575
/**
76-
* @var array
76+
* @var string[]
7777
*/
7878
public const GEOCODE_ADDITIONAL_DATA_PARAMS = [
7979
'CrossingStreets',
@@ -282,6 +282,10 @@ private function getAdditionalDataParam(GeocodeQuery $query): string
282282

283283
/**
284284
* Add API credentials to query params.
285+
*
286+
* @param array<string, string> $queryParams
287+
*
288+
* @return array<string, string>
285289
*/
286290
private function withApiCredentials(array $queryParams): array
287291
{
@@ -323,6 +327,8 @@ public function getBaseUrl(Query $query): string
323327

324328
/**
325329
* Serialize the component query parameter.
330+
*
331+
* @param array<string, string> $components
326332
*/
327333
private function serializeComponents(array $components): string
328334
{

Model/HereAddress.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ final class HereAddress extends Address
3535
private $locationName;
3636

3737
/**
38-
* @var array|null
38+
* @var array<string, mixed>|null
3939
*/
4040
private $additionalData;
4141

4242
/**
43-
* @var array|null
43+
* @var array<string, mixed>|null
4444
*/
4545
private $shape;
4646

@@ -93,13 +93,16 @@ public function withLocationName(string $locationName = null): self
9393
}
9494

9595
/**
96-
* @return array|null
96+
* @return array<string, mixed>|null
9797
*/
9898
public function getAdditionalData()
9999
{
100100
return $this->additionalData;
101101
}
102102

103+
/**
104+
* @param array<string, mixed>|null $additionalData
105+
*/
103106
public function withAdditionalData(array $additionalData = null): self
104107
{
105108
$new = clone $this;
@@ -122,10 +125,7 @@ public function addAdditionalData(string $name, $value = null): self
122125
return $new;
123126
}
124127

125-
/**
126-
* @param mixed|null $default
127-
*/
128-
public function getAdditionalDataValue(string $name, $default = null)
128+
public function getAdditionalDataValue(string $name, mixed $default = null): mixed
129129
{
130130
if ($this->hasAdditionalDataValue($name)) {
131131
return $this->additionalData[$name];
@@ -139,6 +139,9 @@ public function hasAdditionalDataValue(string $name): bool
139139
return array_key_exists($name, $this->additionalData);
140140
}
141141

142+
/**
143+
* @param array<string, mixed>|null $shape
144+
*/
142145
public function withShape(array $shape = null): self
143146
{
144147
$new = clone $this;
@@ -152,18 +155,15 @@ public function withShape(array $shape = null): self
152155
return $new;
153156
}
154157

155-
/**
156-
* @param mixed|null $value
157-
*/
158-
public function addShape(string $name, $value = null): self
158+
public function addShape(string $name, mixed $value = null): self
159159
{
160160
$new = clone $this;
161161
$new->shape[$name] = $value;
162162

163163
return $new;
164164
}
165165

166-
public function getShapeValue(string $name, $default = null)
166+
public function getShapeValue(string $name, mixed $default = null): mixed
167167
{
168168
if ($this->hasShapeValue($name)) {
169169
return $this->shape[$name];

Tests/HereTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
class HereTest extends BaseTestCase
2727
{
28-
protected function getCacheDir()
28+
protected function getCacheDir(): ?string
2929
{
3030
if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) {
3131
return __DIR__.'/.cached_responses';
@@ -34,7 +34,7 @@ protected function getCacheDir()
3434
return null;
3535
}
3636

37-
public function testGeocodeWithRealAddress()
37+
public function testGeocodeWithRealAddress(): void
3838
{
3939
if (!isset($_SERVER['HERE_API_KEY'])) {
4040
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');
@@ -69,7 +69,7 @@ public function testGeocodeWithRealAddress()
6969
/**
7070
* @throws \Geocoder\Exception\Exception
7171
*/
72-
public function testGeocodeWithDefaultAdditionalData()
72+
public function testGeocodeWithDefaultAdditionalData(): void
7373
{
7474
if (!isset($_SERVER['HERE_API_KEY'])) {
7575
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');
@@ -111,7 +111,7 @@ public function testGeocodeWithDefaultAdditionalData()
111111
*
112112
* @throws \Geocoder\Exception\Exception
113113
*/
114-
public function testGeocodeWithAdditionalData()
114+
public function testGeocodeWithAdditionalData(): void
115115
{
116116
if (!isset($_SERVER['HERE_API_KEY'])) {
117117
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');
@@ -161,7 +161,7 @@ public function testGeocodeWithAdditionalData()
161161
*
162162
* @throws \Geocoder\Exception\Exception
163163
*/
164-
public function testGeocodeWithExtraFilterCountry()
164+
public function testGeocodeWithExtraFilterCountry(): void
165165
{
166166
if (!isset($_SERVER['HERE_API_KEY'])) {
167167
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');
@@ -196,7 +196,7 @@ public function testGeocodeWithExtraFilterCountry()
196196
*
197197
* @throws \Geocoder\Exception\Exception
198198
*/
199-
public function testGeocodeWithExtraFilterCity()
199+
public function testGeocodeWithExtraFilterCity(): void
200200
{
201201
if (!isset($_SERVER['HERE_API_KEY'])) {
202202
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');
@@ -234,7 +234,7 @@ public function testGeocodeWithExtraFilterCity()
234234
$this->assertEquals('ESP', $resultCity3->getCountry()->getCode());
235235
}
236236

237-
public function testGeocodeWithExtraFilterCounty()
237+
public function testGeocodeWithExtraFilterCounty(): void
238238
{
239239
if (!isset($_SERVER['HERE_API_KEY'])) {
240240
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');
@@ -268,7 +268,7 @@ public function testGeocodeWithExtraFilterCounty()
268268
$this->assertEquals('ESP', $resultRegion2->getCountry()->getCode());
269269
}
270270

271-
public function testReverseWithRealCoordinates()
271+
public function testReverseWithRealCoordinates(): void
272272
{
273273
if (!isset($_SERVER['HERE_API_KEY'])) {
274274
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');
@@ -298,21 +298,21 @@ public function testReverseWithRealCoordinates()
298298
$this->assertEquals('FRA', $result->getCountry()->getCode());
299299
}
300300

301-
public function testGetName()
301+
public function testGetName(): void
302302
{
303303
$provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode');
304304
$this->assertEquals('Here', $provider->getName());
305305
}
306306

307-
public function testGeocodeWithInvalidData()
307+
public function testGeocodeWithInvalidData(): void
308308
{
309309
$this->expectException(\Geocoder\Exception\InvalidServerResponse::class);
310310

311311
$provider = new Here($this->getMockedHttpClient(), 'appId', 'appCode');
312312
$provider->geocodeQuery(GeocodeQuery::create('foobar'));
313313
}
314314

315-
public function testGeocodeIpv4()
315+
public function testGeocodeIpv4(): void
316316
{
317317
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
318318
$this->expectExceptionMessage('The Here provider does not support IP addresses, only street addresses.');
@@ -321,7 +321,7 @@ public function testGeocodeIpv4()
321321
$provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
322322
}
323323

324-
public function testGeocodeWithLocalhostIPv6()
324+
public function testGeocodeWithLocalhostIPv6(): void
325325
{
326326
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
327327
$this->expectExceptionMessage('The Here provider does not support IP addresses, only street addresses.');
@@ -330,7 +330,7 @@ public function testGeocodeWithLocalhostIPv6()
330330
$provider->geocodeQuery(GeocodeQuery::create('::1'));
331331
}
332332

333-
public function testGeocodeInvalidApiKey()
333+
public function testGeocodeInvalidApiKey(): void
334334
{
335335
$this->expectException(\Geocoder\Exception\InvalidCredentials::class);
336336
$this->expectExceptionMessage('Invalid or missing api key.');
@@ -349,7 +349,7 @@ public function testGeocodeInvalidApiKey()
349349
$provider->geocodeQuery(GeocodeQuery::create('New York'));
350350
}
351351

352-
public function testGeocodeWithRealIPv6()
352+
public function testGeocodeWithRealIPv6(): void
353353
{
354354
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
355355
$this->expectExceptionMessage('The Here provider does not support IP addresses, only street addresses.');
@@ -358,7 +358,7 @@ public function testGeocodeWithRealIPv6()
358358
$provider->geocodeQuery(GeocodeQuery::create('::ffff:88.188.221.14'));
359359
}
360360

361-
public function getProvider()
361+
public function getProvider(): Here
362362
{
363363
if (!isset($_SERVER['HERE_API_KEY'])) {
364364
$this->markTestSkipped('You need to configure the HERE_API_KEY value in phpunit.xml');

Tests/IntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testReverseQueryWithNoResults(): void
200200
* Make sure that a result for a Geocoder is well formatted. Be aware that even
201201
* a Location with no data may be well formatted.
202202
*/
203-
private function assertWellFormattedResult(Collection $result)
203+
private function assertWellFormattedResult(Collection $result): void
204204
{
205205
$this->assertInstanceOf(
206206
Collection::class,

0 commit comments

Comments
 (0)