16
16
class NullCoalesceRuleTest extends RuleTestCase
17
17
{
18
18
19
- private bool $ treatPhpDocTypesAsCertain ;
20
-
21
19
protected function getRule (): Rule
22
20
{
23
21
return new NullCoalesceRule (new IssetCheck (
24
22
new PropertyDescriptor (),
25
23
new PropertyReflectionFinder (),
26
24
true ,
27
- $ this ->treatPhpDocTypesAsCertain ,
25
+ $ this ->shouldTreatPhpDocTypesAsCertain () ,
28
26
));
29
27
}
30
28
31
- protected function shouldTreatPhpDocTypesAsCertain (): bool
32
- {
33
- return $ this ->treatPhpDocTypesAsCertain ;
34
- }
35
-
36
29
public function shouldNarrowMethodScopeFromConstructor (): bool
37
30
{
38
31
return true ;
39
32
}
40
33
41
34
public function testCoalesceRule (): void
42
35
{
43
- $ this ->treatPhpDocTypesAsCertain = true ;
44
36
$ errors = [
45
37
[
46
38
'Property CoalesceRule\FooCoalesce::$string (string) on left side of ?? is not nullable. ' ,
@@ -146,7 +138,6 @@ public function testCoalesceRule(): void
146
138
147
139
public function testCoalesceAssignRule (): void
148
140
{
149
- $ this ->treatPhpDocTypesAsCertain = true ;
150
141
$ this ->analyse ([__DIR__ . '/data/null-coalesce-assign.php ' ], [
151
142
[
152
143
'Property CoalesceAssignRule\FooCoalesce::$string (string) on left side of ??= is not nullable. ' ,
@@ -209,13 +200,11 @@ public function testCoalesceAssignRule(): void
209
200
210
201
public function testNullsafe (): void
211
202
{
212
- $ this ->treatPhpDocTypesAsCertain = true ;
213
203
$ this ->analyse ([__DIR__ . '/data/null-coalesce-nullsafe.php ' ], []);
214
204
}
215
205
216
206
public function testVariableCertaintyInNullCoalesce (): void
217
207
{
218
- $ this ->treatPhpDocTypesAsCertain = true ;
219
208
$ this ->analyse ([__DIR__ . '/data/variable-certainty-null.php ' ], [
220
209
[
221
210
'Variable $scalar on left side of ?? always exists and is not nullable. ' ,
@@ -234,7 +223,6 @@ public function testVariableCertaintyInNullCoalesce(): void
234
223
235
224
public function testVariableCertaintyInNullCoalesceAssign (): void
236
225
{
237
- $ this ->treatPhpDocTypesAsCertain = true ;
238
226
$ this ->analyse ([__DIR__ . '/data/variable-certainty-null-assign.php ' ], [
239
227
[
240
228
'Variable $scalar on left side of ??= always exists and is not nullable. ' ,
@@ -253,7 +241,6 @@ public function testVariableCertaintyInNullCoalesceAssign(): void
253
241
254
242
public function testNullCoalesceInGlobalScope (): void
255
243
{
256
- $ this ->treatPhpDocTypesAsCertain = true ;
257
244
$ this ->analyse ([__DIR__ . '/data/null-coalesce-global-scope.php ' ], [
258
245
[
259
246
'Variable $bar on left side of ?? always exists and is not nullable. ' ,
@@ -264,15 +251,12 @@ public function testNullCoalesceInGlobalScope(): void
264
251
265
252
public function testBug5933 (): void
266
253
{
267
- $ this ->treatPhpDocTypesAsCertain = true ;
268
254
$ this ->analyse ([__DIR__ . '/data/bug-5933.php ' ], []);
269
255
}
270
256
271
257
#[RequiresPhp('>= 8.0 ' )]
272
258
public function testBug7109 (): void
273
259
{
274
- $ this ->treatPhpDocTypesAsCertain = true ;
275
-
276
260
$ this ->analyse ([__DIR__ . '/../Properties/data/bug-7109.php ' ], [
277
261
[
278
262
'Using nullsafe property access "?->aaa" on left side of ?? is unnecessary. Use -> instead. ' ,
@@ -299,8 +283,6 @@ public function testBug7109(): void
299
283
300
284
public function testBug7190 (): void
301
285
{
302
- $ this ->treatPhpDocTypesAsCertain = true ;
303
-
304
286
$ this ->analyse ([__DIR__ . '/../Properties/data/bug-7190.php ' ], [
305
287
[
306
288
'Offset int on array<int, int> on left side of ?? always exists and is not nullable. ' ,
@@ -311,8 +293,6 @@ public function testBug7190(): void
311
293
312
294
public function testBug7318 (): void
313
295
{
314
- $ this ->treatPhpDocTypesAsCertain = true ;
315
-
316
296
$ this ->analyse ([__DIR__ . '/../Properties/data/bug-7318.php ' ], [
317
297
[
318
298
"Offset 'unique' on array{unique: bool} on left side of ?? always exists and is not nullable. " ,
@@ -323,50 +303,37 @@ public function testBug7318(): void
323
303
324
304
public function testBug7968 (): void
325
305
{
326
- $ this ->treatPhpDocTypesAsCertain = true ;
327
-
328
306
$ this ->analyse ([__DIR__ . '/data/bug-7968.php ' ], []);
329
307
}
330
308
331
309
public function testBug8084 (): void
332
310
{
333
- $ this ->treatPhpDocTypesAsCertain = true ;
334
-
335
311
$ this ->analyse ([__DIR__ . '/data/bug-8084.php ' ], []);
336
312
}
337
313
338
314
public function testBug10577 (): void
339
315
{
340
- $ this ->treatPhpDocTypesAsCertain = true ;
341
-
342
316
$ this ->analyse ([__DIR__ . '/data/bug-10577.php ' ], []);
343
317
}
344
318
345
319
public function testBug11708 (): void
346
320
{
347
- $ this ->treatPhpDocTypesAsCertain = true ;
348
-
349
321
$ this ->analyse ([__DIR__ . '/data/bug-11708.php ' ], []);
350
322
}
351
323
352
324
public function testBug10610 (): void
353
325
{
354
- $ this ->treatPhpDocTypesAsCertain = true ;
355
-
356
326
$ this ->analyse ([__DIR__ . '/data/bug-10610.php ' ], []);
357
327
}
358
328
359
329
#[RequiresPhp('>= 8.4 ' )]
360
330
public function testBug12553 (): void
361
331
{
362
- $ this ->treatPhpDocTypesAsCertain = true ;
363
332
$ this ->analyse ([__DIR__ . '/data/bug-12553.php ' ], []);
364
333
}
365
334
366
335
public function testIssetAfterRememberedConstructor (): void
367
336
{
368
- $ this ->treatPhpDocTypesAsCertain = true ;
369
-
370
337
$ this ->analyse ([__DIR__ . '/data/isset-after-remembered-constructor.php ' ], [
371
338
[
372
339
'Property IssetOrCoalesceOnNonNullableInitializedProperty\User::$string on left side of ?? is not nullable nor uninitialized. ' ,
0 commit comments