Skip to content

Commit 722fc19

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 734c5c5. * [WIP] Apply PHPStan fixes * [WIP] Apply PHPStan fixes * Update phpstan-baseline.neon
1 parent a7d67b7 commit 722fc19

File tree

111 files changed

+975
-779
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+975
-779
lines changed

phpstan-baseline.neon

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ parameters:
55
count: 1
66
path: src/Common/ProviderAggregator.php
77

8+
-
9+
message: "#^Method Geocoder\\\\TimedGeocoder\\:\\:__call\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
10+
count: 1
11+
path: src/Common/TimedGeocoder.php
12+
13+
-
14+
message: "#^Method Geocoder\\\\Provider\\\\Cache\\\\ProviderCache\\:\\:__call\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
15+
count: 1
16+
path: src/Provider/Cache/ProviderCache.php
17+
818
-
919
message: "#^Parameter \\#1 \\$locations of class Geocoder\\\\Model\\\\AddressCollection constructor expects array\\<Geocoder\\\\Location\\>, array\\<string, string\\> given\\.$#"
1020
count: 2

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
includes:
22
- phpstan-baseline.neon
33
parameters:
4-
level: 5
4+
level: 6
55
paths:
66
- src
77
excludePaths:

src/Common/Assert.php

+5-11
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,35 @@
1616

1717
class Assert
1818
{
19-
/**
20-
* @param float $value
21-
*/
22-
public static function latitude($value, string $message = '')
19+
public static function latitude(mixed $value, string $message = ''): void
2320
{
2421
self::float($value, $message);
2522
if ($value < -90 || $value > 90) {
2623
throw new InvalidArgument(sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value));
2724
}
2825
}
2926

30-
/**
31-
* @param float $value
32-
*/
33-
public static function longitude($value, string $message = '')
27+
public static function longitude(mixed $value, string $message = ''): void
3428
{
3529
self::float($value, $message);
3630
if ($value < -180 || $value > 180) {
3731
throw new InvalidArgument(sprintf($message ?: 'Longitude should be between -180 and 180. Got: %s', $value));
3832
}
3933
}
4034

41-
public static function notNull($value, string $message = '')
35+
public static function notNull(mixed $value, string $message = ''): void
4236
{
4337
if (null === $value) {
4438
throw new InvalidArgument(sprintf($message ?: 'Value cannot be null'));
4539
}
4640
}
4741

48-
private static function typeToString($value): string
42+
private static function typeToString(mixed $value): string
4943
{
5044
return is_object($value) ? get_class($value) : gettype($value);
5145
}
5246

53-
private static function float($value, string $message)
47+
private static function float(mixed $value, string $message): void
5448
{
5549
if (!is_float($value)) {
5650
throw new InvalidArgument(sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value)));

src/Common/Dumper/AbstractArrayDumper.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020
abstract class AbstractArrayDumper
2121
{
22+
/**
23+
* @return array{type: 'Feature', geometry: array{type: 'Point', coordinates: array{0: float, 1: float}}, properties: array<string, mixed>, bounds?: array{south: float, west: float, north: float, east: float}}
24+
*/
2225
protected function getArray(Location $location): array
2326
{
2427
$properties = array_filter($location->toArray(), function ($value) {

src/Common/Dumper/Dumper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface Dumper
2323
* Dumps an `Location` object as a string representation of
2424
* the implemented format.
2525
*/
26-
public function dump(Location $location);
26+
public function dump(Location $location): mixed;
2727
}

src/Common/Dumper/GeoArray.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020
final class GeoArray extends AbstractArrayDumper implements Dumper
2121
{
22+
/**
23+
* @return array{type: 'Feature', geometry: array{type: 'Point', coordinates: array{0: float, 1: float}}, properties: array<string, mixed>, bounds?: array{south: float, west: float, north: float, east: float}}
24+
*/
2225
public function dump(Location $location): array
2326
{
2427
return $this->getArray($location);

src/Common/Exception/ProviderNotRegistered.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
*/
1818
final class ProviderNotRegistered extends \RuntimeException implements Exception
1919
{
20-
public static function create(string $providerName, array $registeredProviders = [])
20+
/**
21+
* @param string[] $registeredProviders
22+
*/
23+
public static function create(string $providerName, array $registeredProviders = []): self
2124
{
2225
return new self(sprintf(
2326
'Provider "%s" is not registered, so you cannot use it. Did you forget to register it or made a typo?%s',
@@ -26,7 +29,7 @@ public static function create(string $providerName, array $registeredProviders =
2629
));
2730
}
2831

29-
public static function noProviderRegistered()
32+
public static function noProviderRegistered(): self
3033
{
3134
return new self('No provider registered.');
3235
}

src/Common/Location.php

+10-24
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@ interface Location
2727
{
2828
/**
2929
* Will always return the coordinates value object.
30-
*
31-
* @return Coordinates|null
3230
*/
33-
public function getCoordinates();
31+
public function getCoordinates(): ?Coordinates;
3432

3533
/**
3634
* Returns the bounds value object.
37-
*
38-
* @return Bounds|null
3935
*/
40-
public function getBounds();
36+
public function getBounds(): ?Bounds;
4137

4238
/**
4339
* Returns the street number value.
@@ -48,32 +44,24 @@ public function getStreetNumber();
4844

4945
/**
5046
* Returns the street name value.
51-
*
52-
* @return string|null
5347
*/
54-
public function getStreetName();
48+
public function getStreetName(): ?string;
5549

5650
/**
5751
* Returns the city or locality value.
58-
*
59-
* @return string|null
6052
*/
61-
public function getLocality();
53+
public function getLocality(): ?string;
6254

6355
/**
6456
* Returns the postal code or zipcode value.
65-
*
66-
* @return string|null
6757
*/
68-
public function getPostalCode();
58+
public function getPostalCode(): ?string;
6959

7060
/**
7161
* Returns the locality district, or
7262
* sublocality, or neighborhood.
73-
*
74-
* @return string|null
7563
*/
76-
public function getSubLocality();
64+
public function getSubLocality(): ?string;
7765

7866
/**
7967
* Returns the administrative levels.
@@ -84,22 +72,20 @@ public function getAdminLevels(): AdminLevelCollection;
8472

8573
/**
8674
* Returns the country value object.
87-
*
88-
* @return Country|null
8975
*/
90-
public function getCountry();
76+
public function getCountry(): ?Country;
9177

9278
/**
9379
* Returns the timezone for the Location. The timezone MUST be in the list of supported timezones.
9480
*
9581
* {@link http://php.net/manual/en/timezones.php}
96-
*
97-
* @return string|null
9882
*/
99-
public function getTimezone();
83+
public function getTimezone(): ?string;
10084

10185
/**
10286
* Returns an array with data indexed by name.
87+
*
88+
* @return array<string, mixed>
10389
*/
10490
public function toArray(): array;
10591

src/Common/Model/Address.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -105,37 +105,37 @@ public function getProvidedBy(): string
105105
return $this->providedBy;
106106
}
107107

108-
public function getCoordinates()
108+
public function getCoordinates(): ?Coordinates
109109
{
110110
return $this->coordinates;
111111
}
112112

113-
public function getBounds()
113+
public function getBounds(): ?Bounds
114114
{
115115
return $this->bounds;
116116
}
117117

118-
public function getStreetNumber()
118+
public function getStreetNumber(): ?string
119119
{
120120
return $this->streetNumber;
121121
}
122122

123-
public function getStreetName()
123+
public function getStreetName(): ?string
124124
{
125125
return $this->streetName;
126126
}
127127

128-
public function getLocality()
128+
public function getLocality(): ?string
129129
{
130130
return $this->locality;
131131
}
132132

133-
public function getPostalCode()
133+
public function getPostalCode(): ?string
134134
{
135135
return $this->postalCode;
136136
}
137137

138-
public function getSubLocality()
138+
public function getSubLocality(): ?string
139139
{
140140
return $this->subLocality;
141141
}
@@ -145,19 +145,21 @@ public function getAdminLevels(): AdminLevelCollection
145145
return $this->adminLevels;
146146
}
147147

148-
public function getCountry()
148+
public function getCountry(): ?Country
149149
{
150150
return $this->country;
151151
}
152152

153-
public function getTimezone()
153+
public function getTimezone(): ?string
154154
{
155155
return $this->timezone;
156156
}
157157

158158
/**
159159
* Create an Address with an array. Useful for testing.
160160
*
161+
* @param array<string, mixed> $data
162+
*
161163
* @return static
162164
*/
163165
public static function createFromArray(array $data)
@@ -259,7 +261,7 @@ private static function createCountry($name, $code)
259261
*
260262
* @return Bounds|null
261263
*/
262-
private static function createBounds($south, $west, $north, $east)
264+
private static function createBounds(?float $south, ?float $west, ?float $north, ?float $east)
263265
{
264266
if (null === $south || null === $west || null === $north || null === $east) {
265267
return null;

src/Common/Model/AddressBuilder.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class AddressBuilder
6363
private $subLocality;
6464

6565
/**
66-
* @var array
66+
* @var AdminLevel[]
6767
*/
6868
private $adminLevels = [];
6969

@@ -85,7 +85,7 @@ final class AddressBuilder
8585
/**
8686
* A storage for extra parameters.
8787
*
88-
* @var array
88+
* @var array<string, mixed>
8989
*/
9090
private $data = [];
9191

@@ -210,7 +210,7 @@ public function setSubLocality($subLocality): self
210210
}
211211

212212
/**
213-
* @param array $adminLevels
213+
* @param AdminLevel[] $adminLevels
214214
*/
215215
public function setAdminLevels($adminLevels): self
216216
{
@@ -249,17 +249,14 @@ public function setTimezone($timezone): self
249249
return $this;
250250
}
251251

252-
public function setValue(string $name, $value): self
252+
public function setValue(string $name, mixed $value): self
253253
{
254254
$this->data[$name] = $value;
255255

256256
return $this;
257257
}
258258

259-
/**
260-
* @param mixed|null $default
261-
*/
262-
public function getValue(string $name, $default = null)
259+
public function getValue(string $name, mixed $default = null): mixed
263260
{
264261
if ($this->hasValue($name)) {
265262
return $this->data[$name];

src/Common/Model/AdminLevelCollection.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
/**
2020
* @author Giorgio Premi <[email protected]>
21+
*
22+
* @phpstan-implements \IteratorAggregate<int, AdminLevel>
2123
*/
2224
final class AdminLevelCollection implements \IteratorAggregate, \Countable
2325
{
@@ -111,7 +113,7 @@ public function all(): array
111113
/**
112114
* @throws \OutOfBoundsException
113115
*/
114-
private function checkLevel(int $level)
116+
private function checkLevel(int $level): void
115117
{
116118
if ($level <= 0 || $level > self::MAX_LEVEL_DEPTH) {
117119
throw new OutOfBounds(sprintf('Administrative level should be an integer in [1,%d], %d given', self::MAX_LEVEL_DEPTH, $level));

src/Common/Model/Bounds.php

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public function getEast(): float
102102

103103
/**
104104
* Returns an array with bounds.
105+
*
106+
* @return array{south: float, west: float, north: float, east: float}
105107
*/
106108
public function toArray(): array
107109
{

src/Common/Model/Coordinates.php

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function getLongitude(): float
6666

6767
/**
6868
* Returns the coordinates as a tuple.
69+
*
70+
* @return array{float, float}
6971
*/
7072
public function toArray(): array
7173
{

0 commit comments

Comments
 (0)