@@ -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,185 @@ 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+ 'Call to an undefined static method object::create(). ' ,
1190+ 133 ,
1191+ ],
1192+ [
1193+ 'Call to an undefined static method T of object::create(). ' ,
1194+ 142 ,
1195+ ],
1196+ [
1197+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1198+ 150 ,
1199+ ],
1200+ [
1201+ 'Call to private static method privateMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1202+ 162 ,
1203+ ],
1204+ [
1205+ 'Call to protected static method protectedMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1206+ 163 ,
1207+ ],
1208+ [
1209+ 'Call to static method create() on an unknown class StaticCallStringUnions\UnknownClass. ' ,
1210+ 171 ,
1211+ 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ,
1212+ ],
1213+ ]);
1214+ }
1215+
1216+ #[RequiresPhp('>= 8.0.0 ' )]
1217+ public function testStaticCallsOnStringUnionsWithoutCheckUnionTypes (): void
1218+ {
1219+ $ this ->checkThisOnly = false ;
1220+ $ this ->checkUnionTypes = 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::create(). ' ,
1228+ 87 ,
1229+ ],
1230+ [
1231+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1232+ 101 ,
1233+ ],
1234+ [
1235+ 'Call to an undefined static method StaticCallStringUnions\WithMagic::whatever(). ' ,
1236+ 107 ,
1237+ ],
1238+ [
1239+ 'Call to an undefined static method object::create(). ' ,
1240+ 133 ,
1241+ ],
1242+ [
1243+ 'Call to an undefined static method T of object::create(). ' ,
1244+ 142 ,
1245+ ],
1246+ [
1247+ 'Call to private static method privateMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1248+ 162 ,
1249+ ],
1250+ [
1251+ 'Call to protected static method protectedMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1252+ 163 ,
1253+ ],
1254+ [
1255+ 'Call to static method create() on an unknown class StaticCallStringUnions\UnknownClass. ' ,
1256+ 171 ,
1257+ 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ,
1258+ ],
1259+ ]);
1260+ }
1261+
1262+ #[RequiresPhp('>= 8.0.0 ' )]
1263+ public function testStaticCallsOnStringUnionsWithoutReportMagicMethods (): void
1264+ {
1265+ $ this ->checkThisOnly = false ;
1266+ $ this ->reportMagicMethods = false ;
1267+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1268+ [
1269+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1270+ 53 ,
1271+ ],
1272+ [
1273+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1274+ 59 ,
1275+ ],
1276+ [
1277+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1278+ 71 ,
1279+ ],
1280+ [
1281+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1282+ 79 ,
1283+ ],
1284+ [
1285+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1286+ 87 ,
1287+ ],
1288+ [
1289+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1290+ 101 ,
1291+ ],
1292+ [
1293+ 'Call to an undefined static method object::create(). ' ,
1294+ 133 ,
1295+ ],
1296+ [
1297+ 'Call to an undefined static method T of object::create(). ' ,
1298+ 142 ,
1299+ ],
1300+ [
1301+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1302+ 150 ,
1303+ ],
1304+ [
1305+ 'Call to private static method privateMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1306+ 162 ,
1307+ ],
1308+ [
1309+ 'Call to protected static method protectedMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1310+ 163 ,
1311+ ],
1312+ [
1313+ 'Call to static method create() on an unknown class StaticCallStringUnions\UnknownClass. ' ,
1314+ 171 ,
1315+ 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ,
1316+ ],
1317+ ]);
1318+ }
1319+
11351320}
0 commit comments