@@ -23,7 +23,7 @@ protected function getRule(): Rule
2323 new PropertyReflectionFinder (),
2424 true ,
2525 $ this ->shouldTreatPhpDocTypesAsCertain (),
26- ));
26+ ), true );
2727 }
2828
2929 public function testCoalesceRule (): void
@@ -386,12 +386,20 @@ public function testPr4372(): void
386386
387387 public function testBug14213 (): void
388388 {
389- $ this ->analyse ([__DIR__ . '/../../Analyser/nsrt/bug-14213.php ' ], [
390- [
391- 'Variable $x1 on left side of ?? always exists and is always null. ' ,
392- 22 ,
393- ],
394- ]);
389+ $ errors = [];
390+ if (PHP_VERSION_ID >= 80100 ) {
391+ // This is only detected with FiberScope.
392+ $ errors [] = [
393+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
394+ 21 ,
395+ ];
396+ }
397+ $ errors [] = [
398+ 'Variable $x1 on left side of ?? always exists and is always null. ' ,
399+ 22 ,
400+ ];
401+
402+ $ this ->analyse ([__DIR__ . '/../../Analyser/nsrt/bug-14213.php ' ], $ errors );
395403 }
396404
397405 public function testBug11488 (): void
@@ -452,6 +460,72 @@ public function testBug14459Hooked(): void
452460 ]);
453461 }
454462
463+ public function testBug4337 (): void
464+ {
465+ $ this ->analyse ([__DIR__ . '/data/bug-4337.php ' ], [
466+ [
467+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
468+ 37 ,
469+ ],
470+ [
471+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
472+ 42 ,
473+ ],
474+ [
475+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
476+ 47 ,
477+ ],
478+ [
479+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
480+ 53 ,
481+ ],
482+ [
483+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
484+ 58 ,
485+ ],
486+ [
487+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
488+ 63 ,
489+ ],
490+ [
491+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
492+ 69 ,
493+ ],
494+ [
495+ 'Coalesce operator ??= is unnecessary because the left side is always set and the right side is null. ' ,
496+ 75 ,
497+ ],
498+ ]);
499+ }
500+
501+ public function testBug12179 (): void
502+ {
503+ $ this ->analyse ([__DIR__ . '/data/bug-12179.php ' ], [
504+ [
505+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
506+ 8 ,
507+ ],
508+ [
509+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
510+ 24 ,
511+ ],
512+ ]);
513+ }
514+
515+ public function testBug9966 (): void
516+ {
517+ $ this ->analyse ([__DIR__ . '/data/bug-9966.php ' ], [
518+ [
519+ 'Offset \'key1 \' on array{key1: string, key2: string|null, key3?: string, key4?: string|null} on left side of ?? always exists and is not nullable. ' ,
520+ 9 ,
521+ ],
522+ [
523+ 'Coalesce operator ?? is unnecessary because the left side is always set and the right side is null. ' ,
524+ 12 ,
525+ ],
526+ ]);
527+ }
528+
455529 public function testBug14393 (): void
456530 {
457531 $ this ->analyse ([__DIR__ . '/data/bug-14393.php ' ], [
0 commit comments