Skip to content

Commit 0bfee99

Browse files
committed
feat: migrate PHPStan 1 => 2
1 parent 55afe87 commit 0bfee99

File tree

5 files changed

+50
-52
lines changed

5 files changed

+50
-52
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
},
8080
"scripts": {
8181
"test": "SYMFONY_DEPRECATIONS_HELPER=ignoreFile='./tests/baseline-ignore' vendor/bin/simple-phpunit --testsuite main",
82-
"phpstan": "vendor/bin/phpstan --memory-limit=1024m"
82+
"phpstan": "vendor/bin/phpstan analyse --memory-limit=1024m",
83+
"phpstan-baseline": "vendor/bin/phpstan analyse --generate-baseline phpstan-baseline.php --memory-limit=1024m"
8384
},
8485
"config": {
8586
"allow-plugins": {

phpstan-baseline.php

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,206 +4,206 @@
44

55
$ignoreErrors = [];
66
$ignoreErrors[] = [
7-
// identifier: argument.type
87
'message' => '#^Parameter \\#1 \\$name of method Geocoder\\\\ProviderAggregator\\:\\:using\\(\\) expects string, mixed given\\.$#',
8+
'identifier' => 'argument.type',
99
'count' => 1,
1010
'path' => __DIR__.'/src/Command/GeocodeCommand.php',
1111
];
1212
$ignoreErrors[] = [
13-
// identifier: argument.type
1413
'message' => '#^Parameter \\#1 \\$string of function strtolower expects string, string\\|null given\\.$#',
14+
'identifier' => 'argument.type',
1515
'count' => 1,
1616
'path' => __DIR__.'/src/Command/GeocodeCommand.php',
1717
];
1818
$ignoreErrors[] = [
19-
// identifier: argument.type
2019
'message' => '#^Parameter \\#1 \\$text of static method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:create\\(\\) expects string, mixed given\\.$#',
20+
'identifier' => 'argument.type',
2121
'count' => 1,
2222
'path' => __DIR__.'/src/Command/GeocodeCommand.php',
2323
];
2424
$ignoreErrors[] = [
25-
// identifier: argument.type
2625
'message' => '#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#',
26+
'identifier' => 'argument.type',
2727
'count' => 1,
2828
'path' => __DIR__.'/src/Command/GeocodeCommand.php',
2929
];
3030
$ignoreErrors[] = [
31-
// identifier: foreach.nonIterable
31+
'message' => '#^Method Bazinga\\\\GeocoderBundle\\\\DataCollector\\\\GeocoderDataCollector\\:\\:getProviderQueries\\(\\) should return list\\<array\\{query\\: Geocoder\\\\Query\\\\Query, queryString\\: string, duration\\: float, providerName\\: string, result\\: mixed, resultCount\\: int\\}\\> but returns array\\.$#',
32+
'identifier' => 'return.type',
33+
'count' => 1,
34+
'path' => __DIR__.'/src/DataCollector/GeocoderDataCollector.php',
35+
];
36+
$ignoreErrors[] = [
3237
'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#',
38+
'identifier' => 'foreach.nonIterable',
3339
'count' => 3,
3440
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
3541
];
3642
$ignoreErrors[] = [
37-
// identifier: offsetAccess.nonOffsetAccessible
43+
'message' => '#^Binary operation "\\." between \'bazinga_geocoder…\' and mixed results in an error\\.$#',
44+
'identifier' => 'binaryOp.invalid',
45+
'count' => 1,
46+
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
47+
];
48+
$ignoreErrors[] = [
3849
'message' => '#^Cannot access offset \'aliases\' on mixed\\.$#',
50+
'identifier' => 'offsetAccess.nonOffsetAccessible',
3951
'count' => 1,
4052
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
4153
];
4254
$ignoreErrors[] = [
43-
// identifier: offsetAccess.nonOffsetAccessible
4455
'message' => '#^Cannot access offset \'enabled\' on mixed\\.$#',
56+
'identifier' => 'offsetAccess.nonOffsetAccessible',
4557
'count' => 1,
4658
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
4759
];
4860
$ignoreErrors[] = [
49-
// identifier: offsetAccess.nonOffsetAccessible
5061
'message' => '#^Cannot access offset \'factory\' on mixed\\.$#',
62+
'identifier' => 'offsetAccess.nonOffsetAccessible',
5163
'count' => 5,
5264
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
5365
];
5466
$ignoreErrors[] = [
55-
// identifier: offsetAccess.nonOffsetAccessible
5667
'message' => '#^Cannot access offset \'id\' on mixed\\.$#',
68+
'identifier' => 'offsetAccess.nonOffsetAccessible',
5769
'count' => 1,
5870
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
5971
];
6072
$ignoreErrors[] = [
61-
// identifier: offsetAccess.nonOffsetAccessible
6273
'message' => '#^Cannot access offset \'options\' on mixed\\.$#',
74+
'identifier' => 'offsetAccess.nonOffsetAccessible',
6375
'count' => 4,
6476
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
6577
];
6678
$ignoreErrors[] = [
67-
// identifier: offsetAccess.nonOffsetAccessible
6879
'message' => '#^Cannot access offset \'reference\' on mixed\\.$#',
80+
'identifier' => 'offsetAccess.nonOffsetAccessible',
6981
'count' => 2,
7082
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
7183
];
7284
$ignoreErrors[] = [
73-
// identifier: staticMethod.nonObject
7485
'message' => '#^Cannot call static method validate\\(\\) on mixed\\.$#',
86+
'identifier' => 'staticMethod.nonObject',
7587
'count' => 1,
7688
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
7789
];
7890
$ignoreErrors[] = [
79-
// identifier: cast.string
8091
'message' => '#^Cannot cast mixed to string\\.$#',
92+
'identifier' => 'cast.string',
8193
'count' => 1,
8294
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
8395
];
8496
$ignoreErrors[] = [
85-
// identifier: argument.type
8697
'message' => '#^Parameter \\#1 \\$alias of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:setAlias\\(\\) expects string, mixed given\\.$#',
98+
'identifier' => 'argument.type',
8799
'count' => 1,
88100
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
89101
];
90102
$ignoreErrors[] = [
91-
// identifier: argument.type
92103
'message' => '#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: Symfony\\\\Component\\\\DependencyInjection\\\\Reference given\\.$#',
104+
'identifier' => 'argument.type',
93105
'count' => 1,
94106
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
95107
];
96108
$ignoreErrors[] = [
97-
// identifier: argument.type
98109
'message' => '#^Parameter \\#1 \\$factoryServiceId of static method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\Compiler\\\\FactoryValidatorPass\\:\\:addFactoryServiceId\\(\\) expects non\\-empty\\-string, mixed given\\.$#',
110+
'identifier' => 'argument.type',
99111
'count' => 1,
100112
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
101113
];
102114
$ignoreErrors[] = [
103-
// identifier: argument.type
104115
'message' => '#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#',
116+
'identifier' => 'argument.type',
105117
'count' => 1,
106118
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
107119
];
108120
$ignoreErrors[] = [
109-
// identifier: argument.type
110121
'message' => '#^Parameter \\#1 \\$id of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:getDefinition\\(\\) expects string, mixed given\\.$#',
122+
'identifier' => 'argument.type',
111123
'count' => 1,
112124
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
113125
];
114126
$ignoreErrors[] = [
115-
// identifier: argument.type
116127
'message' => '#^Parameter \\#1 \\$object_or_class of function class_implements expects object\\|string, mixed given\\.$#',
128+
'identifier' => 'argument.type',
117129
'count' => 1,
118130
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
119131
];
120132
$ignoreErrors[] = [
121-
// identifier: argument.type
122-
'message' => '#^Parameter \\#1 \\$options of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:findReferences\\(\\) expects array\\<int\\|string, mixed\\>, mixed given\\.$#',
133+
'message' => '#^Parameter \\#1 \\$options of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:findReferences\\(\\) expects array\\<mixed\\>, mixed given\\.$#',
134+
'identifier' => 'argument.type',
123135
'count' => 2,
124136
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
125137
];
126138
$ignoreErrors[] = [
127-
// identifier: argument.type
128139
'message' => '#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#',
140+
'identifier' => 'argument.type',
129141
'count' => 1,
130142
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
131143
];
132144
$ignoreErrors[] = [
133-
// identifier: argument.type
134145
'message' => '#^Parameter \\#2 \\$array of function array_key_exists expects array, array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null given\\.$#',
146+
'identifier' => 'argument.type',
135147
'count' => 1,
136148
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
137149
];
138150
$ignoreErrors[] = [
139-
// identifier: argument.type
140-
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array, mixed given\\.$#',
151+
'message' => '#^Parameter \\#2 \\$config of method Bazinga\\\\GeocoderBundle\\\\DependencyInjection\\\\BazingaGeocoderExtension\\:\\:configureProviderPlugins\\(\\) expects array\\<mixed\\>, mixed given\\.$#',
152+
'identifier' => 'argument.type',
141153
'count' => 1,
142154
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
143155
];
144156
$ignoreErrors[] = [
145-
// identifier: argument.type
146157
'message' => '#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#',
158+
'identifier' => 'argument.type',
147159
'count' => 1,
148160
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
149161
];
150162
$ignoreErrors[] = [
151-
// identifier: encapsedStringPart.nonString
152163
'message' => '#^Part \\$providerName \\(mixed\\) of encapsed string cannot be cast to string\\.$#',
164+
'identifier' => 'encapsedStringPart.nonString',
153165
'count' => 1,
154166
'path' => __DIR__.'/src/DependencyInjection/BazingaGeocoderExtension.php',
155167
];
156168
$ignoreErrors[] = [
157-
// identifier: method.nonObject
158169
'message' => '#^Cannot call method getLatitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#',
170+
'identifier' => 'method.nonObject',
159171
'count' => 1,
160172
'path' => __DIR__.'/src/Doctrine/ORM/GeocodeEntityListener.php',
161173
];
162174
$ignoreErrors[] = [
163-
// identifier: method.nonObject
164175
'message' => '#^Cannot call method getLongitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#',
176+
'identifier' => 'method.nonObject',
165177
'count' => 1,
166178
'path' => __DIR__.'/src/Doctrine/ORM/GeocodeEntityListener.php',
167179
];
168180
$ignoreErrors[] = [
169-
// identifier: argument.missing
170-
'message' => '#^Missing parameter \\$provider \\(string\\) in call to Bazinga\\\\GeocoderBundle\\\\Mapping\\\\ClassMetadata constructor\\.$#',
171-
'count' => 1,
172-
'path' => __DIR__.'/src/Mapping/Driver/AttributeDriver.php',
173-
];
174-
$ignoreErrors[] = [
175-
// identifier: argument.type
176181
'message' => '#^Parameter \\#1 \\$text of method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:withText\\(\\) expects string, string\\|null given\\.$#',
182+
'identifier' => 'argument.type',
177183
'count' => 1,
178184
'path' => __DIR__.'/src/Plugin/FakeIpPlugin.php',
179185
];
180186
$ignoreErrors[] = [
181-
// identifier: argument.type
182-
'message' => '#^Parameter \\#2 \\$replace of function str_replace expects array\\|string, string\\|null given\\.$#',
183-
'count' => 1,
184-
'path' => __DIR__.'/src/Plugin/FakeIpPlugin.php',
185-
];
186-
$ignoreErrors[] = [
187-
// identifier: argument.type
188187
'message' => '#^Parameter \\#1 \\$accountId of class GeoIp2\\\\WebService\\\\Client constructor expects int, int\\|null given\\.$#',
188+
'identifier' => 'argument.type',
189189
'count' => 1,
190190
'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php',
191191
];
192192
$ignoreErrors[] = [
193-
// identifier: argument.type
194193
'message' => '#^Parameter \\#1 \\$filename of class GeoIp2\\\\Database\\\\Reader constructor expects string, string\\|null given\\.$#',
194+
'identifier' => 'argument.type',
195195
'count' => 1,
196196
'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php',
197197
];
198198
$ignoreErrors[] = [
199-
// identifier: argument.type
200199
'message' => '#^Parameter \\#1 \\$geoIpProvider of class Geocoder\\\\Provider\\\\GeoIP2\\\\GeoIP2Adapter constructor expects GeoIp2\\\\ProviderInterface, GeoIp2\\\\ProviderInterface\\|null given\\.$#',
200+
'identifier' => 'argument.type',
201201
'count' => 1,
202202
'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php',
203203
];
204204
$ignoreErrors[] = [
205-
// identifier: argument.type
206205
'message' => '#^Parameter \\#2 \\$licenseKey of class GeoIp2\\\\WebService\\\\Client constructor expects string, string\\|null given\\.$#',
206+
'identifier' => 'argument.type',
207207
'count' => 1,
208208
'path' => __DIR__.'/src/ProviderFactory/GeoIP2Factory.php',
209209
];

phpstan.dist.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ parameters:
88
- src/
99
#- tests/
1010
level: 9
11+
treatPhpDocTypesAsCertain: false

src/Plugin/FakeIpPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function handleQuery(Query $query, callable $next, callable $first)
5454
$replacement = $this->faker->ipv4();
5555
}
5656

57-
if (null !== $this->needle && '' !== $this->needle) {
57+
if (null !== $this->needle && '' !== $this->needle && $replacement) {
5858
$text = str_replace($this->needle, $replacement, $query->getText(), $count);
5959

6060
if ($count > 0) {

src/ProviderFactory/HereFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ protected function getProvider(array $config): Provider
3636
$httpClient = $config['http_client'] ?? $this->httpClient ?? Psr18ClientDiscovery::find();
3737

3838
if (!empty($config['app_key'])) {
39-
if (!method_exists(Here::class, 'createUsingApiKey')) {
40-
throw new \InvalidArgumentException('Here provider has no support for `creatingUsingApiKey` method.');
41-
}
42-
4339
return Here::createUsingApiKey($httpClient, $config['app_key'], $config['use_cit']);
4440
}
4541

0 commit comments

Comments
 (0)