@@ -26,14 +26,15 @@ protected function getRule(): Rule
26
26
$ reflectionProvider = self ::createReflectionProvider ();
27
27
return new ClassConstantRule (
28
28
$ reflectionProvider ,
29
- new RuleLevelHelper ($ reflectionProvider , true , false , true , false , false , false , true ),
29
+ new RuleLevelHelper ($ reflectionProvider , true , false , true , true , true , false , true ),
30
30
new ClassNameCheck (
31
31
new ClassCaseSensitivityCheck ($ reflectionProvider , true ),
32
32
new ClassForbiddenNameCheck (self ::getContainer ()),
33
33
$ reflectionProvider ,
34
34
self ::getContainer (),
35
35
),
36
36
new PhpVersion ($ this ->phpVersion ),
37
+ true ,
37
38
);
38
39
}
39
40
@@ -59,6 +60,10 @@ public function testClassConstant(): void
59
60
'Access to undefined constant ClassConstantNamespace\Foo::DOLOR. ' ,
60
61
10 ,
61
62
],
63
+ [
64
+ 'Cannot access constant LOREM on mixed. ' ,
65
+ 11 ,
66
+ ],
62
67
[
63
68
'Access to undefined constant ClassConstantNamespace\Foo::DOLOR. ' ,
64
69
16 ,
@@ -439,6 +444,14 @@ public function testDynamicAccess(): void
439
444
$ this ->phpVersion = PHP_VERSION_ID ;
440
445
441
446
$ this ->analyse ([__DIR__ . '/data/dynamic-constant-access.php ' ], [
447
+ [
448
+ 'Access to undefined constant ClassConstantDynamicAccess\Foo::FOO. ' ,
449
+ 17 ,
450
+ ],
451
+ [
452
+ 'Class constant name for ClassConstantDynamicAccess\Foo must be a string, but object was given. ' ,
453
+ 19 ,
454
+ ],
442
455
[
443
456
'Access to undefined constant ClassConstantDynamicAccess\Foo::FOO. ' ,
444
457
20 ,
@@ -474,4 +487,61 @@ public function testDynamicAccess(): void
474
487
]);
475
488
}
476
489
490
+ #[RequiresPhp('>= 8.3 ' )]
491
+ public function testStringableDynamicAccess (): void
492
+ {
493
+ $ this ->phpVersion = PHP_VERSION_ID ;
494
+
495
+ $ this ->analyse ([__DIR__ . '/data/dynamic-constant-stringable-access.php ' ], [
496
+ [
497
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but mixed was given. ' ,
498
+ 14 ,
499
+ ],
500
+ [
501
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but string|null was given. ' ,
502
+ 15 ,
503
+ ],
504
+ [
505
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but Stringable|null was given. ' ,
506
+ 16 ,
507
+ ],
508
+ [
509
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but int was given. ' ,
510
+ 17 ,
511
+ ],
512
+ [
513
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but int|null was given. ' ,
514
+ 18 ,
515
+ ],
516
+ [
517
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but DateTime|string was given. ' ,
518
+ 19 ,
519
+ ],
520
+ [
521
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but 1111 was given. ' ,
522
+ 20 ,
523
+ ],
524
+ [
525
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but Stringable was given. ' ,
526
+ 22 ,
527
+ ],
528
+ [
529
+ 'Class constant name for ClassConstantDynamicStringableAccess\Foo must be a string, but mixed was given. ' ,
530
+ 32 ,
531
+ ],
532
+ [
533
+ 'Class constant name for ClassConstantDynamicStringableAccess\Bar must be a string, but mixed was given. ' ,
534
+ 33 ,
535
+ ],
536
+ [
537
+ 'Class constant name for DateTime|DateTimeImmutable must be a string, but mixed was given. ' ,
538
+ 38 ,
539
+ ],
540
+ [
541
+ 'Class constant name for object must be a string, but mixed was given. ' ,
542
+ 39 ,
543
+ ],
544
+ ]);
545
+ }
546
+
477
547
}
0 commit comments