Skip to content

Commit 02e0450

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 a618c4a commit 02e0450

File tree

3 files changed

+43
-64
lines changed

3 files changed

+43
-64
lines changed

Mapbox.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class Mapbox extends AbstractHttpProvider implements Provider
4848
public const GEOCODING_MODE_PLACES_PERMANENT = 'mapbox.places-permanent';
4949

5050
/**
51-
* @var array
51+
* @var string[]
5252
*/
5353
public const GEOCODING_MODES = [
5454
self::GEOCODING_MODE_PLACES,
@@ -106,7 +106,7 @@ final class Mapbox extends AbstractHttpProvider implements Provider
106106
public const TYPE_POI_LANDMARK = 'poi.landmark';
107107

108108
/**
109-
* @var array
109+
* @var string[]
110110
*/
111111
public const TYPES = [
112112
self::TYPE_COUNTRY,
@@ -121,6 +121,9 @@ final class Mapbox extends AbstractHttpProvider implements Provider
121121
self::TYPE_POI_LANDMARK,
122122
];
123123

124+
/**
125+
* @var string
126+
*/
124127
public const DEFAULT_TYPE = self::TYPE_ADDRESS;
125128

126129
/**
@@ -305,10 +308,10 @@ private function fetchUrl(string $url, int $limit, string $locale = null, string
305308
/**
306309
* Update current resultSet with given key/value.
307310
*
308-
* @param string $type Component type
309-
* @param array $value The component value
311+
* @param string $type Component type
312+
* @param array<string, mixed> $value Component value
310313
*/
311-
private function updateAddressComponent(AddressBuilder $builder, string $type, array $value)
314+
private function updateAddressComponent(AddressBuilder $builder, string $type, array $value): void
312315
{
313316
$typeParts = explode('.', $type);
314317
$type = reset($typeParts);
@@ -359,9 +362,9 @@ private function updateAddressComponent(AddressBuilder $builder, string $type, a
359362
/**
360363
* Decode the response content and validate it to make sure it does not have any errors.
361364
*
362-
* @param string $content
365+
* @return array<string, mixed>
363366
*/
364-
private function validateResponse(string $url, $content): array
367+
private function validateResponse(string $url, string $content): array
365368
{
366369
$json = json_decode($content, true);
367370

@@ -375,8 +378,10 @@ private function validateResponse(string $url, $content): array
375378

376379
/**
377380
* Parse coordinats and bounds.
381+
*
382+
* @param array<string, mixed> $result
378383
*/
379-
private function parseCoordinates(AddressBuilder $builder, array $result)
384+
private function parseCoordinates(AddressBuilder $builder, array $result): void
380385
{
381386
$coordinates = $result['geometry']['coordinates'];
382387
$builder->setCoordinates($coordinates[1], $coordinates[0]);

Model/MapboxAddress.php

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class MapboxAddress extends Address
3232
private $streetName;
3333

3434
/**
35-
* @var array
35+
* @var string[]
3636
*/
3737
private $resultType = [];
3838

@@ -46,10 +46,7 @@ final class MapboxAddress extends Address
4646
*/
4747
private $neighborhood;
4848

49-
/**
50-
* @return MapboxAddress
51-
*/
52-
public function withId(string $id = null)
49+
public function withId(string $id = null): self
5350
{
5451
$new = clone $this;
5552
$new->id = $id;
@@ -59,99 +56,76 @@ public function withId(string $id = null)
5956

6057
/**
6158
* @see https://www.mapbox.com/api-documentation/?language=cURL#response-object
62-
*
63-
* @return string|null
6459
*/
65-
public function getId()
60+
public function getId(): ?string
6661
{
6762
return $this->id;
6863
}
6964

70-
/**
71-
* @return string|null
72-
*/
73-
public function getStreetName()
65+
public function getStreetName(): ?string
7466
{
7567
return $this->streetName;
7668
}
7769

78-
/**
79-
* @return MapboxAddress
80-
*/
81-
public function withStreetName(string $streetName = null)
70+
public function withStreetName(string $streetName = null): self
8271
{
8372
$new = clone $this;
8473
$new->streetName = $streetName;
8574

8675
return $new;
8776
}
8877

89-
/**
90-
* @return string|int|null
91-
*/
92-
public function getStreetNumber()
78+
public function getStreetNumber(): ?string
9379
{
9480
return $this->streetNumber;
9581
}
9682

97-
/**
98-
* @return MapboxAddress
99-
*/
100-
public function withStreetNumber(string $streetNumber = null)
83+
public function withStreetNumber(string $streetNumber = null): self
10184
{
10285
$new = clone $this;
10386
$new->streetNumber = $streetNumber;
10487

10588
return $new;
10689
}
10790

91+
/**
92+
* @return string[]
93+
*/
10894
public function getResultType(): array
10995
{
11096
return $this->resultType;
11197
}
11298

11399
/**
114-
* @return MapboxAddress
100+
* @param string[] $resultType
115101
*/
116-
public function withResultType(array $resultType)
102+
public function withResultType(array $resultType): self
117103
{
118104
$new = clone $this;
119105
$new->resultType = $resultType;
120106

121107
return $new;
122108
}
123109

124-
/**
125-
* @return string|null
126-
*/
127-
public function getFormattedAddress()
110+
public function getFormattedAddress(): ?string
128111
{
129112
return $this->formattedAddress;
130113
}
131114

132-
/**
133-
* @return MapboxAddress
134-
*/
135-
public function withFormattedAddress(string $formattedAddress = null)
115+
public function withFormattedAddress(string $formattedAddress = null): self
136116
{
137117
$new = clone $this;
138118
$new->formattedAddress = $formattedAddress;
139119

140120
return $new;
141121
}
142122

143-
/**
144-
* @return string|null
145-
*/
146-
public function getNeighborhood()
123+
public function getNeighborhood(): ?string
147124
{
148125
return $this->neighborhood;
149126
}
150127

151-
/**
152-
* @return MapboxAddress
153-
*/
154-
public function withNeighborhood(string $neighborhood = null)
128+
public function withNeighborhood(string $neighborhood = null): self
155129
{
156130
$new = clone $this;
157131
$new->neighborhood = $neighborhood;

Tests/MapboxTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class MapboxTest extends BaseTestCase
2424
{
25-
protected function getCacheDir()
25+
protected function getCacheDir(): ?string
2626
{
2727
if (isset($_SERVER['USE_CACHED_RESPONSES']) && true === $_SERVER['USE_CACHED_RESPONSES']) {
2828
return __DIR__.'/.cached_responses';
@@ -31,13 +31,13 @@ protected function getCacheDir()
3131
return null;
3232
}
3333

34-
public function testGetName()
34+
public function testGetName(): void
3535
{
3636
$provider = new Mapbox($this->getMockedHttpClient(), 'access_token');
3737
$this->assertEquals('mapbox', $provider->getName());
3838
}
3939

40-
public function testGeocodeWithLocalhostIPv4()
40+
public function testGeocodeWithLocalhostIPv4(): void
4141
{
4242
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
4343
$this->expectExceptionMessage('The Mapbox provider does not support IP addresses, only street addresses.');
@@ -46,7 +46,7 @@ public function testGeocodeWithLocalhostIPv4()
4646
$provider->geocodeQuery(GeocodeQuery::create('127.0.0.1'));
4747
}
4848

49-
public function testGeocodeWithLocalhostIPv6()
49+
public function testGeocodeWithLocalhostIPv6(): void
5050
{
5151
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
5252
$this->expectExceptionMessage('The Mapbox provider does not support IP addresses, only street addresses.');
@@ -55,7 +55,7 @@ public function testGeocodeWithLocalhostIPv6()
5555
$provider->geocodeQuery(GeocodeQuery::create('::1'));
5656
}
5757

58-
public function testGeocodeWithRealIp()
58+
public function testGeocodeWithRealIp(): void
5959
{
6060
$this->expectException(\Geocoder\Exception\UnsupportedOperation::class);
6161
$this->expectExceptionMessage('The Mapbox provider does not support IP addresses, only street addresses.');
@@ -64,15 +64,15 @@ public function testGeocodeWithRealIp()
6464
$provider->geocodeQuery(GeocodeQuery::create('74.200.247.59'));
6565
}
6666

67-
public function testGeocodeWithQuotaExceeded()
67+
public function testGeocodeWithQuotaExceeded(): void
6868
{
6969
$this->expectException(\Geocoder\Exception\QuotaExceeded::class);
7070

7171
$provider = new Mapbox($this->getMockedHttpClient('', 429), 'access_token');
7272
$provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France'));
7373
}
7474

75-
public function testGeocodePlaceWithNoCountryShortCode()
75+
public function testGeocodePlaceWithNoCountryShortCode(): void
7676
{
7777
$provider = new Mapbox($this->getHttpClient($_SERVER['MAPBOX_GEOCODING_KEY']), $_SERVER['MAPBOX_GEOCODING_KEY']);
7878

@@ -115,7 +115,7 @@ public function testGeocodePlaceWithNoCountryShortCode()
115115
$this->assertNull($result->getStreetNumber());
116116
}
117117

118-
public function testGeocodeWithRealAddress()
118+
public function testGeocodeWithRealAddress(): void
119119
{
120120
if (!isset($_SERVER['MAPBOX_GEOCODING_KEY'])) {
121121
$this->markTestSkipped('You need to configure the MAPBOX_GEOCODING_KEY value in phpunit.xml');
@@ -148,15 +148,15 @@ public function testGeocodeWithRealAddress()
148148
$this->assertNull($result->getTimezone());
149149
}
150150

151-
public function testReverse()
151+
public function testReverse(): void
152152
{
153153
$this->expectException(\Geocoder\Exception\InvalidServerResponse::class);
154154

155155
$provider = new Mapbox($this->getMockedHttpClient(), 'access_token');
156156
$provider->reverseQuery(ReverseQuery::fromCoordinates(1, 2));
157157
}
158158

159-
public function testReverseWithRealCoordinates()
159+
public function testReverseWithRealCoordinates(): void
160160
{
161161
if (!isset($_SERVER['MAPBOX_GEOCODING_KEY'])) {
162162
$this->markTestSkipped('You need to configure the MAPBOX_GEOCODING_KEY value in phpunit.xml');
@@ -182,15 +182,15 @@ public function testReverseWithRealCoordinates()
182182
$this->assertEquals('address.1085979616', $result->getId());
183183
}
184184

185-
public function testGeocodeWithInvalidApiKey()
185+
public function testGeocodeWithInvalidApiKey(): void
186186
{
187187
$this->expectException(\Geocoder\Exception\InvalidCredentials::class);
188188

189189
$provider = new Mapbox($this->getMockedHttpClient('', 403), 'api_key');
190190
$provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France'));
191191
}
192192

193-
public function testGeocodeWithRealValidApiKey()
193+
public function testGeocodeWithRealValidApiKey(): void
194194
{
195195
if (!isset($_SERVER['MAPBOX_GEOCODING_KEY'])) {
196196
$this->markTestSkipped('You need to configure the MAPBOX_GEOCODING_KEY value in phpunit.xml');
@@ -222,7 +222,7 @@ public function testGeocodeWithRealValidApiKey()
222222
$this->assertEquals('NY', $result->getAdminLevels()->get(2)->getCode());
223223
}
224224

225-
public function testGeocodeWithFuzzyMatch()
225+
public function testGeocodeWithFuzzyMatch(): void
226226
{
227227
if (!isset($_SERVER['MAPBOX_GEOCODING_KEY'])) {
228228
$this->markTestSkipped('You need to configure the MAPBOX_GEOCODING_KEY value in phpunit.xml');
@@ -244,7 +244,7 @@ public function testGeocodeWithFuzzyMatch()
244244
$this->assertCount(5, $results);
245245
}
246246

247-
public function testGeocodeWithoutFuzzyMatch()
247+
public function testGeocodeWithoutFuzzyMatch(): void
248248
{
249249
if (!isset($_SERVER['MAPBOX_GEOCODING_KEY'])) {
250250
$this->markTestSkipped('You need to configure the MAPBOX_GEOCODING_KEY value in phpunit.xml');

0 commit comments

Comments
 (0)