@@ -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+ 'Cannot fetch class constant with a non-stringable type object. ' ,
453+ 19 ,
454+ ],
442455 [
443456 'Access to undefined constant ClassConstantDynamicAccess\Foo::FOO. ' ,
444457 20 ,
@@ -474,4 +487,41 @@ 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+ 'Cannot fetch class constant with a non-stringable type mixed. ' ,
498+ 13 ,
499+ ],
500+ [
501+ 'Cannot fetch class constant with a non-stringable type string|null. ' ,
502+ 14 ,
503+ ],
504+ [
505+ 'Cannot fetch class constant with a non-stringable type Stringable|null. ' ,
506+ 15 ,
507+ ],
508+ [
509+ 'Cannot fetch class constant with a non-stringable type int. ' ,
510+ 16 ,
511+ ],
512+ [
513+ 'Cannot fetch class constant with a non-stringable type int|null. ' ,
514+ 17 ,
515+ ],
516+ [
517+ 'Cannot fetch class constant with a non-stringable type DateTime|string. ' ,
518+ 18 ,
519+ ],
520+ [
521+ 'Cannot fetch class constant with a non-stringable type 1111. ' ,
522+ 19 ,
523+ ],
524+ ]);
525+ }
526+
477527}
0 commit comments