@@ -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 ,
@@ -1156,4 +1160,185 @@ public function testBug11421(): void
11561160 ]);
11571161 }
11581162
1163+ #[RequiresPhp('>= 8.1.0 ' )]
1164+ public function testBug11353 (): void
1165+ {
1166+ $ this ->checkThisOnly = false ;
1167+ $ this ->analyse ([__DIR__ . '/data/bug-11353.php ' ], [
1168+ [
1169+ 'Call to an undefined static method Bug11353\A|Bug11353\B|Bug11353\C::create(). ' ,
1170+ 46 ,
1171+ ],
1172+ ]);
1173+ }
1174+
1175+ #[RequiresPhp('>= 8.0.0 ' )]
1176+ public function testStaticCallsOnStringUnions (): void
1177+ {
1178+ $ this ->checkThisOnly = false ;
1179+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1180+ [
1181+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1182+ 53 ,
1183+ ],
1184+ [
1185+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1186+ 59 ,
1187+ ],
1188+ [
1189+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1190+ 71 ,
1191+ ],
1192+ [
1193+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1194+ 79 ,
1195+ ],
1196+ [
1197+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1198+ 87 ,
1199+ ],
1200+ [
1201+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1202+ 101 ,
1203+ ],
1204+ [
1205+ 'Call to an undefined static method StaticCallStringUnions\WithMagic::whatever(). ' ,
1206+ 107 ,
1207+ ],
1208+ [
1209+ 'Call to an undefined static method StaticCallStringUnions\Foo|StaticCallStringUnions\WithMagic::create(). ' ,
1210+ 115 ,
1211+ ],
1212+ [
1213+ 'Call to an undefined static method object::create(). ' ,
1214+ 133 ,
1215+ ],
1216+ [
1217+ 'Call to an undefined static method T of object::create(). ' ,
1218+ 142 ,
1219+ ],
1220+ [
1221+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1222+ 150 ,
1223+ ],
1224+ [
1225+ 'Call to private static method privateMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1226+ 162 ,
1227+ ],
1228+ [
1229+ 'Call to protected static method protectedMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1230+ 163 ,
1231+ ],
1232+ [
1233+ 'Call to static method create() on an unknown class StaticCallStringUnions\UnknownClass. ' ,
1234+ 171 ,
1235+ 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ,
1236+ ],
1237+ ]);
1238+ }
1239+
1240+ #[RequiresPhp('>= 8.0.0 ' )]
1241+ public function testStaticCallsOnStringUnionsWithoutCheckUnionTypes (): void
1242+ {
1243+ $ this ->checkThisOnly = false ;
1244+ $ this ->checkUnionTypes = false ;
1245+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1246+ [
1247+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1248+ 53 ,
1249+ ],
1250+ [
1251+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1252+ 87 ,
1253+ ],
1254+ [
1255+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1256+ 101 ,
1257+ ],
1258+ [
1259+ 'Call to an undefined static method StaticCallStringUnions\WithMagic::whatever(). ' ,
1260+ 107 ,
1261+ ],
1262+ [
1263+ 'Call to an undefined static method object::create(). ' ,
1264+ 133 ,
1265+ ],
1266+ [
1267+ 'Call to an undefined static method T of object::create(). ' ,
1268+ 142 ,
1269+ ],
1270+ [
1271+ 'Call to private static method privateMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1272+ 162 ,
1273+ ],
1274+ [
1275+ 'Call to protected static method protectedMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1276+ 163 ,
1277+ ],
1278+ [
1279+ 'Call to static method create() on an unknown class StaticCallStringUnions\UnknownClass. ' ,
1280+ 171 ,
1281+ 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ,
1282+ ],
1283+ ]);
1284+ }
1285+
1286+ #[RequiresPhp('>= 8.0.0 ' )]
1287+ public function testStaticCallsOnStringUnionsWithoutReportMagicMethods (): void
1288+ {
1289+ $ this ->checkThisOnly = false ;
1290+ $ this ->reportMagicMethods = false ;
1291+ $ this ->analyse ([__DIR__ . '/data/static-call-string-unions.php ' ], [
1292+ [
1293+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1294+ 53 ,
1295+ ],
1296+ [
1297+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1298+ 59 ,
1299+ ],
1300+ [
1301+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1302+ 71 ,
1303+ ],
1304+ [
1305+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1306+ 79 ,
1307+ ],
1308+ [
1309+ 'Call to an undefined static method StaticCallStringUnions\Baz::create(). ' ,
1310+ 87 ,
1311+ ],
1312+ [
1313+ 'Static call to instance method StaticCallStringUnions\Foo::doBar(). ' ,
1314+ 101 ,
1315+ ],
1316+ [
1317+ 'Call to an undefined static method object::create(). ' ,
1318+ 133 ,
1319+ ],
1320+ [
1321+ 'Call to an undefined static method T of object::create(). ' ,
1322+ 142 ,
1323+ ],
1324+ [
1325+ 'Call to an undefined static method StaticCallStringUnions\Baz|StaticCallStringUnions\Foo::create(). ' ,
1326+ 150 ,
1327+ ],
1328+ [
1329+ 'Call to private static method privateMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1330+ 162 ,
1331+ ],
1332+ [
1333+ 'Call to protected static method protectedMethod() of class StaticCallStringUnions\WithNonPublic. ' ,
1334+ 163 ,
1335+ ],
1336+ [
1337+ 'Call to static method create() on an unknown class StaticCallStringUnions\UnknownClass. ' ,
1338+ 171 ,
1339+ 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ,
1340+ ],
1341+ ]);
1342+ }
1343+
11591344}
0 commit comments