@@ -26,14 +26,15 @@ protected function getRule(): Rule
2626 $ reflectionProvider = self ::createReflectionProvider ();
2727 return new ClassConstantRule (
2828 $ reflectionProvider ,
29- new RuleLevelHelper ($ reflectionProvider , true , false , true , false , false , false , true ),
29+ new RuleLevelHelper ($ reflectionProvider , true , false , true , true , true , false , true ),
3030 new ClassNameCheck (
3131 new ClassCaseSensitivityCheck ($ reflectionProvider , true ),
3232 new ClassForbiddenNameCheck (self ::getContainer ()),
3333 $ reflectionProvider ,
3434 self ::getContainer (),
3535 ),
3636 new PhpVersion ($ this ->phpVersion ),
37+ true ,
3738 );
3839 }
3940
@@ -59,6 +60,10 @@ public function testClassConstant(): void
5960 'Access to undefined constant ClassConstantNamespace\Foo::DOLOR. ' ,
6061 10 ,
6162 ],
63+ [
64+ 'Cannot access constant LOREM on mixed. ' ,
65+ 11 ,
66+ ],
6267 [
6368 'Access to undefined constant ClassConstantNamespace\Foo::DOLOR. ' ,
6469 16 ,
@@ -439,6 +444,14 @@ public function testDynamicAccess(): void
439444 $ this ->phpVersion = PHP_VERSION_ID ;
440445
441446 $ 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+ ],
442455 [
443456 'Access to undefined constant ClassConstantDynamicAccess\Foo::FOO. ' ,
444457 20 ,
@@ -474,4 +487,61 @@ public function testDynamicAccess(): void
474487 ]);
475488 }
476489
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+
477547}
0 commit comments