@@ -25,18 +25,22 @@ class CallStaticMethodsRuleTest extends RuleTestCase
2525
2626 private bool $ checkThisOnly ;
2727
28+ private bool $ checkUnionTypes = true ;
29+
2830 private bool $ checkExplicitMixed = false ;
2931
3032 private bool $ checkImplicitMixed = false ;
3133
34+ private bool $ reportMagicMethods = true ;
35+
3236 protected function getRule (): Rule
3337 {
3438 $ reflectionProvider = self ::createReflectionProvider ();
3539 $ ruleLevelHelper = new RuleLevelHelper (
3640 $ reflectionProvider ,
3741 checkNullables: true ,
3842 checkThisOnly: $ this ->checkThisOnly ,
39- checkUnionTypes: true ,
43+ checkUnionTypes: $ this -> checkUnionTypes ,
4044 checkExplicitMixed: $ this ->checkExplicitMixed ,
4145 checkImplicitMixed: $ this ->checkImplicitMixed ,
4246 checkBenevolentUnionTypes: false ,
@@ -58,7 +62,7 @@ protected function getRule(): Rule
5862 ),
5963 checkFunctionNameCase: true ,
6064 discoveringSymbolsTip: true ,
61- reportMagicMethods: true ,
65+ reportMagicMethods: $ this -> reportMagicMethods ,
6266 ),
6367 new FunctionCallParametersCheck (
6468 $ ruleLevelHelper ,
@@ -1057,4 +1061,114 @@ public function testClassExistOnCall(): void
10571061 $ this ->analyse ([__DIR__ . '/data/class-exists-on-static-call.php ' ], []);
10581062 }
10591063
1064+ #[RequiresPhp('>= 8.1.0 ' )]
1065+ public function testBug11353 (): void
1066+ {
1067+ $ this ->checkThisOnly = false ;
1068+ $ this ->analyse ([__DIR__ . '/data/bug-11353.php ' ], [
1069+ [
1070+ 'Call to an undefined static method Bug11353\A|Bug11353\B|Bug11353\C::create(). ' ,
1071+ 46 ,
1072+ ],
1073+ ]);
1074+ }
1075+
1076+ #[RequiresPhp('>= 8.0.0 ' )]
1077+ public function testStaticCallsOnStringUnions (): void
1078+ {
1079+ $ this ->checkThisOnly = false ;
1080+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1081+ [
1082+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1083+ 53 ,
1084+ ],
1085+ [
1086+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1087+ 59 ,
1088+ ],
1089+ [
1090+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1091+ 71 ,
1092+ ],
1093+ [
1094+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1095+ 79 ,
1096+ ],
1097+ [
1098+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1099+ 87 ,
1100+ ],
1101+ [
1102+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1103+ 101 ,
1104+ ],
1105+ [
1106+ 'Call to an undefined static method StaticCallStringUnions\WithMagic::whatever(). ' ,
1107+ 107 ,
1108+ ],
1109+ [
1110+ 'Call to an undefined static method StaticCallStringUnions\Foo|StaticCallStringUnions\WithMagic::create(). ' ,
1111+ 115 ,
1112+ ],
1113+ ]);
1114+ }
1115+
1116+ #[RequiresPhp('>= 8.0.0 ' )]
1117+ public function testStaticCallsOnStringUnionsWithoutCheckUnionTypes (): void
1118+ {
1119+ $ this ->checkThisOnly = false ;
1120+ $ this ->checkUnionTypes = false ;
1121+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1122+ [
1123+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1124+ 53 ,
1125+ ],
1126+ [
1127+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1128+ 87 ,
1129+ ],
1130+ [
1131+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1132+ 101 ,
1133+ ],
1134+ [
1135+ 'Call to an undefined static method StaticCallStringUnions\WithMagic::whatever(). ' ,
1136+ 107 ,
1137+ ],
1138+ ]);
1139+ }
1140+
1141+ #[RequiresPhp('>= 8.0.0 ' )]
1142+ public function testStaticCallsOnStringUnionsWithoutReportMagicMethods (): void
1143+ {
1144+ $ this ->checkThisOnly = false ;
1145+ $ this ->reportMagicMethods = false ;
1146+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1147+ [
1148+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1149+ 53 ,
1150+ ],
1151+ [
1152+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1153+ 59 ,
1154+ ],
1155+ [
1156+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1157+ 71 ,
1158+ ],
1159+ [
1160+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1161+ 79 ,
1162+ ],
1163+ [
1164+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1165+ 87 ,
1166+ ],
1167+ [
1168+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1169+ 101 ,
1170+ ],
1171+ ]);
1172+ }
1173+
10601174}
0 commit comments