18
18
19
19
class GetListTableDynamicFunctionReturnTypeExtension implements \PHPStan \Type \DynamicFunctionReturnTypeExtension
20
20
{
21
+ private const CORE_CLASSES = [
22
+ 'WP_Posts_List_Table ' ,
23
+ 'WP_Media_List_Table ' ,
24
+ 'WP_Terms_List_Table ' ,
25
+ 'WP_Users_List_Table ' ,
26
+ 'WP_Comments_List_Table ' ,
27
+ 'WP_Post_Comments_List_Table ' ,
28
+ 'WP_Links_List_Table ' ,
29
+ 'WP_Plugin_Install_List_Table ' ,
30
+ 'WP_Themes_List_Table ' ,
31
+ 'WP_Theme_Install_List_Table ' ,
32
+ 'WP_Plugins_List_Table ' ,
33
+ 'WP_Application_Passwords_List_Table ' ,
34
+ 'WP_MS_Sites_List_Table ' ,
35
+ 'WP_MS_Users_List_Table ' ,
36
+ 'WP_MS_Themes_List_Table ' ,
37
+ 'WP_Privacy_Data_Export_Requests_List_Table ' ,
38
+ 'WP_Privacy_Data_Removal_Requests_List_Table ' ,
39
+ ];
40
+
21
41
public function isFunctionSupported (FunctionReflection $ functionReflection ): bool
22
42
{
23
43
return $ functionReflection ->getName () === '_get_list_table ' ;
@@ -30,7 +50,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
30
50
31
51
// Called without $class argument
32
52
if (count ($ args ) < 1 ) {
33
- return new ConstantBooleanType ( false ) ;
53
+ return null ;
34
54
}
35
55
36
56
$ argumentType = $ scope ->getType ($ args [0 ]->value );
@@ -40,9 +60,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
40
60
return null ;
41
61
}
42
62
43
- $ types = [new ConstantBooleanType ( false ) ];
63
+ $ types = [];
44
64
foreach ($ argumentType ->getConstantStrings () as $ constantString ) {
45
- $ types [] = new ObjectType ($ constantString ->getValue ());
65
+ $ types [] = in_array ($ constantString ->getValue (), self ::CORE_CLASSES , true )
66
+ ? new ObjectType ($ constantString ->getValue ())
67
+ : new ConstantBooleanType (false );
46
68
}
47
69
48
70
return TypeCombinator::union (...$ types );
0 commit comments