@@ -30,18 +30,22 @@ class CallStaticMethodsRuleTest extends RuleTestCase
3030
3131 private bool $ checkThisOnly ;
3232
33+ private bool $ checkUnionTypes = true ;
34+
3335 private bool $ checkExplicitMixed = false ;
3436
3537 private bool $ checkImplicitMixed = false ;
3638
39+ private bool $ reportMagicMethods = true ;
40+
3741 protected function getRule (): Rule
3842 {
3943 $ reflectionProvider = self ::createReflectionProvider ();
4044 $ ruleLevelHelper = new RuleLevelHelper (
4145 $ reflectionProvider ,
4246 checkNullables: $ this ->checkNullables ,
4347 checkThisOnly: $ this ->checkThisOnly ,
44- checkUnionTypes: true ,
48+ checkUnionTypes: $ this -> checkUnionTypes ,
4549 checkExplicitMixed: $ this ->checkExplicitMixed ,
4650 checkImplicitMixed: $ this ->checkImplicitMixed ,
4751 checkBenevolentUnionTypes: false ,
@@ -64,7 +68,7 @@ protected function getRule(): Rule
6468 ),
6569 checkFunctionNameCase: true ,
6670 discoveringSymbolsTip: true ,
67- reportMagicMethods: true ,
71+ reportMagicMethods: $ this -> reportMagicMethods ,
6872 ),
6973 new FunctionCallParametersCheck (
7074 $ ruleLevelHelper ,
@@ -1132,4 +1136,114 @@ public function testBug15251(): void
11321136 ]);
11331137 }
11341138
1139+ #[RequiresPhp('>= 8.1.0 ' )]
1140+ public function testBug11353 (): void
1141+ {
1142+ $ this ->checkThisOnly = false ;
1143+ $ this ->analyse ([__DIR__ . '/data/bug-11353.php ' ], [
1144+ [
1145+ 'Call to an undefined static method Bug11353\A|Bug11353\B|Bug11353\C::create(). ' ,
1146+ 46 ,
1147+ ],
1148+ ]);
1149+ }
1150+
1151+ #[RequiresPhp('>= 8.0.0 ' )]
1152+ public function testStaticCallsOnStringUnions (): void
1153+ {
1154+ $ this ->checkThisOnly = false ;
1155+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1156+ [
1157+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1158+ 53 ,
1159+ ],
1160+ [
1161+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1162+ 59 ,
1163+ ],
1164+ [
1165+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1166+ 71 ,
1167+ ],
1168+ [
1169+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1170+ 79 ,
1171+ ],
1172+ [
1173+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1174+ 87 ,
1175+ ],
1176+ [
1177+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1178+ 101 ,
1179+ ],
1180+ [
1181+ 'Call to an undefined static method StaticCallStringUnions\WithMagic::whatever(). ' ,
1182+ 107 ,
1183+ ],
1184+ [
1185+ 'Call to an undefined static method StaticCallStringUnions\Foo|StaticCallStringUnions\WithMagic::create(). ' ,
1186+ 115 ,
1187+ ],
1188+ ]);
1189+ }
1190+
1191+ #[RequiresPhp('>= 8.0.0 ' )]
1192+ public function testStaticCallsOnStringUnionsWithoutCheckUnionTypes (): void
1193+ {
1194+ $ this ->checkThisOnly = false ;
1195+ $ this ->checkUnionTypes = false ;
1196+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1197+ [
1198+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1199+ 53 ,
1200+ ],
1201+ [
1202+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1203+ 87 ,
1204+ ],
1205+ [
1206+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1207+ 101 ,
1208+ ],
1209+ [
1210+ 'Call to an undefined static method StaticCallStringUnions\WithMagic::whatever(). ' ,
1211+ 107 ,
1212+ ],
1213+ ]);
1214+ }
1215+
1216+ #[RequiresPhp('>= 8.0.0 ' )]
1217+ public function testStaticCallsOnStringUnionsWithoutReportMagicMethods (): void
1218+ {
1219+ $ this ->checkThisOnly = false ;
1220+ $ this ->reportMagicMethods = false ;
1221+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1222+ [
1223+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1224+ 53 ,
1225+ ],
1226+ [
1227+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1228+ 59 ,
1229+ ],
1230+ [
1231+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1232+ 71 ,
1233+ ],
1234+ [
1235+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1236+ 79 ,
1237+ ],
1238+ [
1239+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1240+ 87 ,
1241+ ],
1242+ [
1243+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1244+ 101 ,
1245+ ],
1246+ ]);
1247+ }
1248+
11351249}
0 commit comments