@@ -17,16 +17,13 @@ class IssetRuleTest extends RuleTestCase
17
17
18
18
private bool $ treatPhpDocTypesAsCertain ;
19
19
20
- private bool $ strictUnnecessaryNullsafePropertyFetch ;
21
-
22
20
protected function getRule (): Rule
23
21
{
24
22
return new IssetRule (new IssetCheck (
25
23
new PropertyDescriptor (),
26
24
new PropertyReflectionFinder (),
27
25
true ,
28
26
$ this ->treatPhpDocTypesAsCertain ,
29
- $ this ->strictUnnecessaryNullsafePropertyFetch ,
30
27
));
31
28
}
32
29
@@ -38,7 +35,6 @@ protected function shouldTreatPhpDocTypesAsCertain(): bool
38
35
public function testRule (): void
39
36
{
40
37
$ this ->treatPhpDocTypesAsCertain = true ;
41
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
42
38
$ this ->analyse ([__DIR__ . '/data/isset.php ' ], [
43
39
[
44
40
'Property IssetRule\FooCoalesce::$string (string) in isset() is not nullable. ' ,
@@ -126,7 +122,6 @@ public function testRule(): void
126
122
public function testRuleWithoutTreatPhpDocTypesAsCertain (): void
127
123
{
128
124
$ this ->treatPhpDocTypesAsCertain = false ;
129
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
130
125
$ this ->analyse ([__DIR__ . '/data/isset.php ' ], [
131
126
[
132
127
'Property IssetRule\FooCoalesce::$string (string) in isset() is not nullable. ' ,
@@ -206,7 +201,6 @@ public function testRuleWithoutTreatPhpDocTypesAsCertain(): void
206
201
public function testNativePropertyTypes (): void
207
202
{
208
203
$ this ->treatPhpDocTypesAsCertain = true ;
209
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
210
204
$ this ->analyse ([__DIR__ . '/data/isset-native-property-types.php ' ], [
211
205
/*[
212
206
// no way to achieve this with current PHP Reflection API
@@ -225,14 +219,12 @@ public function testNativePropertyTypes(): void
225
219
public function testBug4290 (): void
226
220
{
227
221
$ this ->treatPhpDocTypesAsCertain = true ;
228
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
229
222
$ this ->analyse ([__DIR__ . '/data/bug-4290.php ' ], []);
230
223
}
231
224
232
225
public function testBug4671 (): void
233
226
{
234
227
$ this ->treatPhpDocTypesAsCertain = true ;
235
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
236
228
$ this ->analyse ([__DIR__ . '/data/bug-4671.php ' ], [[
237
229
'Offset numeric-string on array<string, string> in isset() does not exist. ' ,
238
230
13 ,
@@ -242,7 +234,6 @@ public function testBug4671(): void
242
234
public function testVariableCertaintyInIsset (): void
243
235
{
244
236
$ this ->treatPhpDocTypesAsCertain = true ;
245
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
246
237
$ this ->analyse ([__DIR__ . '/data/variable-certainty-isset.php ' ], [
247
238
[
248
239
'Variable $alwaysDefinedNotNullable in isset() always exists and is not nullable. ' ,
@@ -318,7 +309,6 @@ public function testVariableCertaintyInIsset(): void
318
309
public function testIssetInGlobalScope (): void
319
310
{
320
311
$ this ->treatPhpDocTypesAsCertain = true ;
321
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
322
312
$ this ->analyse ([__DIR__ . '/data/isset-global-scope.php ' ], [
323
313
[
324
314
'Variable $alwaysDefinedNotNullable in isset() always exists and is not nullable. ' ,
@@ -330,35 +320,21 @@ public function testIssetInGlobalScope(): void
330
320
public function testNullsafe (): void
331
321
{
332
322
$ this ->treatPhpDocTypesAsCertain = true ;
333
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
334
- $ this ->analyse ([__DIR__ . '/data/isset-nullsafe.php ' ], []);
335
- }
336
-
337
- public function testBug7109 (): void
338
- {
339
- if (PHP_VERSION_ID < 80000 ) {
340
- $ this ->markTestSkipped ('Test requires PHP 8.0. ' );
341
- }
342
-
343
- $ this ->treatPhpDocTypesAsCertain = true ;
344
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
345
-
346
- $ this ->analyse ([__DIR__ . '/../Properties/data/bug-7109.php ' ], [
323
+ $ this ->analyse ([__DIR__ . '/data/isset-nullsafe.php ' ], [
347
324
[
348
- 'Expression in isset() is not nullable . ' ,
349
- 41 ,
325
+ 'Using nullsafe property access "?->bla" in isset() is unnecessary. Use -> instead . ' ,
326
+ 10 ,
350
327
],
351
328
]);
352
329
}
353
330
354
- public function testBug7109Strict (): void
331
+ public function testBug7109 (): void
355
332
{
356
333
if (PHP_VERSION_ID < 80000 ) {
357
334
$ this ->markTestSkipped ('Test requires PHP 8.0. ' );
358
335
}
359
336
360
337
$ this ->treatPhpDocTypesAsCertain = true ;
361
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
362
338
363
339
$ this ->analyse ([__DIR__ . '/../Properties/data/bug-7109.php ' ], [
364
340
[
@@ -387,7 +363,6 @@ public function testBug7109Strict(): void
387
363
public function testBug7318 (): void
388
364
{
389
365
$ this ->treatPhpDocTypesAsCertain = true ;
390
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
391
366
392
367
$ this ->analyse ([__DIR__ . '/../Properties/data/bug-7318.php ' ], [
393
368
[
@@ -400,15 +375,13 @@ public function testBug7318(): void
400
375
public function testBug6163 (): void
401
376
{
402
377
$ this ->treatPhpDocTypesAsCertain = true ;
403
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
404
378
405
379
$ this ->analyse ([__DIR__ . '/data/bug-6163.php ' ], []);
406
380
}
407
381
408
382
public function testBug6997 (): void
409
383
{
410
384
$ this ->treatPhpDocTypesAsCertain = true ;
411
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
412
385
413
386
$ this ->analyse ([__DIR__ . '/data/bug-6997.php ' ], []);
414
387
}
@@ -420,31 +393,27 @@ public function testBug7776(): void
420
393
}
421
394
422
395
$ this ->treatPhpDocTypesAsCertain = true ;
423
- $ this ->strictUnnecessaryNullsafePropertyFetch = false ;
424
396
425
397
$ this ->analyse ([__DIR__ . '/../../Analyser/nsrt/bug-7776.php ' ], []);
426
398
}
427
399
428
400
public function testBug6008 (): void
429
401
{
430
402
$ this ->treatPhpDocTypesAsCertain = true ;
431
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
432
403
433
404
$ this ->analyse ([__DIR__ . '/data/bug-6008.php ' ], []);
434
405
}
435
406
436
407
public function testBug7292 (): void
437
408
{
438
409
$ this ->treatPhpDocTypesAsCertain = true ;
439
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
440
410
441
411
$ this ->analyse ([__DIR__ . '/data/bug-7292.php ' ], []);
442
412
}
443
413
444
414
public function testObjectShapes (): void
445
415
{
446
416
$ this ->treatPhpDocTypesAsCertain = true ;
447
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
448
417
449
418
// could be checked but current is not
450
419
$ this ->analyse ([__DIR__ . '/data/isset-object-shapes.php ' ], []);
@@ -453,15 +422,13 @@ public function testObjectShapes(): void
453
422
public function testBug10151 (): void
454
423
{
455
424
$ this ->treatPhpDocTypesAsCertain = true ;
456
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
457
425
458
426
$ this ->analyse ([__DIR__ . '/data/bug-10151.php ' ], []);
459
427
}
460
428
461
429
public function testBug3985 (): void
462
430
{
463
431
$ this ->treatPhpDocTypesAsCertain = true ;
464
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
465
432
466
433
$ this ->analyse ([__DIR__ . '/../../Analyser/nsrt/bug-3985.php ' ], [
467
434
[
@@ -478,7 +445,6 @@ public function testBug3985(): void
478
445
public function testBug10064 (): void
479
446
{
480
447
$ this ->treatPhpDocTypesAsCertain = true ;
481
- $ this ->strictUnnecessaryNullsafePropertyFetch = true ;
482
448
483
449
$ this ->analyse ([__DIR__ . '/data/bug-10064.php ' ], []);
484
450
}
0 commit comments