@@ -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,44 @@ public function testDynamicAccess(): void
474487 ]);
475488 }
476489
490+ public function testStringableDynamicAccess (): void
491+ {
492+ if (PHP_VERSION_ID < 80300 ) {
493+ $ this ->markTestSkipped ('Test requires PHP 8.3. ' );
494+ }
495+
496+ $ this ->phpVersion = PHP_VERSION_ID ;
497+
498+ $ this ->analyse ([__DIR__ . '/data/dynamic-constant-stringable-access.php ' ], [
499+ [
500+ 'Cannot fetch class constant with a non-stringable type mixed. ' ,
501+ 13 ,
502+ ],
503+ [
504+ 'Cannot fetch class constant with a non-stringable type string|null. ' ,
505+ 14 ,
506+ ],
507+ [
508+ 'Cannot fetch class constant with a non-stringable type Stringable|null. ' ,
509+ 15 ,
510+ ],
511+ [
512+ 'Cannot fetch class constant with a non-stringable type int. ' ,
513+ 16 ,
514+ ],
515+ [
516+ 'Cannot fetch class constant with a non-stringable type int|null. ' ,
517+ 17 ,
518+ ],
519+ [
520+ 'Cannot fetch class constant with a non-stringable type DateTime|string. ' ,
521+ 18 ,
522+ ],
523+ [
524+ 'Cannot fetch class constant with a non-stringable type 1111. ' ,
525+ 19 ,
526+ ],
527+ ]);
528+ }
529+
477530}
0 commit comments