Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the specificity of the return type of _get_list_table() #210

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @link https://github.com/phpstan/phpstan-src/blob/1.10.x/resources/functionMap.php
*/
return [
'_get_list_table' => ["(\$class_name is 'WP_Posts_List_Table'|'WP_Media_List_Table'|'WP_Terms_List_Table'|'WP_Users_List_Table'|'WP_Comments_List_Table'|'WP_Post_Comments_List_Table'|'WP_Links_List_Table'|'WP_Plugin_Install_List_Table'|'WP_Themes_List_Table'|'WP_Theme_Install_List_Table'|'WP_Plugins_List_Table'|'WP_Application_Passwords_List_Table'|'WP_MS_Sites_List_Table'|'WP_MS_Users_List_Table'|'WP_MS_Themes_List_Table'|'WP_Privacy_Data_Export_Requests_List_Table'|'WP_Privacy_Data_Removal_Requests_List_Table' ? \WP_List_Table : false)", 'args' => 'array{screen?: string}'],
'_get_list_table' => ["(\$class_name is 'WP_Posts_List_Table'|'WP_Media_List_Table'|'WP_Terms_List_Table'|'WP_Users_List_Table'|'WP_Comments_List_Table'|'WP_Post_Comments_List_Table'|'WP_Links_List_Table'|'WP_Plugin_Install_List_Table'|'WP_Themes_List_Table'|'WP_Theme_Install_List_Table'|'WP_Plugins_List_Table'|'WP_Application_Passwords_List_Table'|'WP_MS_Sites_List_Table'|'WP_MS_Users_List_Table'|'WP_MS_Themes_List_Table'|'WP_Privacy_Data_Export_Requests_List_Table'|'WP_Privacy_Data_Removal_Requests_List_Table' ? T : false)", '@phpstan-template' => 'T', 'class_name' => 'class-string<T>', 'args' => 'array{screen?: string}'],
'addslashes_gpc' => ['T', '@phpstan-template' => 'T', 'gpc' => 'T'],
'add_submenu_page' => [null, 'callback' => "''|callable"],
'have_posts' => [null, '@phpstan-impure' => ''],
Expand Down
34 changes: 17 additions & 17 deletions tests/data/_get_list_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

assertType('false', _get_list_table('Not_WP_List_Table'));

assertType('WP_List_Table', _get_list_table('WP_Posts_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Media_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Terms_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Users_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Comments_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Post_Comments_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Links_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Plugin_Install_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Themes_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Theme_Install_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Plugins_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Application_Passwords_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_MS_Sites_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_MS_Users_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_MS_Themes_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Privacy_Data_Export_Requests_List_Table'));
assertType('WP_List_Table', _get_list_table('WP_Privacy_Data_Removal_Requests_List_Table'));
assertType('WP_Posts_List_Table', _get_list_table('WP_Posts_List_Table'));
assertType('WP_Media_List_Table', _get_list_table('WP_Media_List_Table'));
assertType('WP_Terms_List_Table', _get_list_table('WP_Terms_List_Table'));
assertType('WP_Users_List_Table', _get_list_table('WP_Users_List_Table'));
assertType('WP_Comments_List_Table', _get_list_table('WP_Comments_List_Table'));
assertType('WP_Post_Comments_List_Table', _get_list_table('WP_Post_Comments_List_Table'));
assertType('WP_Links_List_Table', _get_list_table('WP_Links_List_Table'));
assertType('WP_Plugin_Install_List_Table', _get_list_table('WP_Plugin_Install_List_Table'));
assertType('WP_Themes_List_Table', _get_list_table('WP_Themes_List_Table'));
assertType('WP_Theme_Install_List_Table', _get_list_table('WP_Theme_Install_List_Table'));
assertType('WP_Plugins_List_Table', _get_list_table('WP_Plugins_List_Table'));
assertType('WP_Application_Passwords_List_Table', _get_list_table('WP_Application_Passwords_List_Table'));
assertType('WP_MS_Sites_List_Table', _get_list_table('WP_MS_Sites_List_Table'));
assertType('WP_MS_Users_List_Table', _get_list_table('WP_MS_Users_List_Table'));
assertType('WP_MS_Themes_List_Table', _get_list_table('WP_MS_Themes_List_Table'));
assertType('WP_Privacy_Data_Export_Requests_List_Table', _get_list_table('WP_Privacy_Data_Export_Requests_List_Table'));
assertType('WP_Privacy_Data_Removal_Requests_List_Table', _get_list_table('WP_Privacy_Data_Removal_Requests_List_Table'));
4 changes: 3 additions & 1 deletion wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -86439,8 +86439,10 @@ function wp_get_popular_importers()
* @param string $class_name The type of the list table, which is the class name.
* @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
* @return WP_List_Table|false List table object on success, false if the class does not exist.
* @phpstan-template T
* @phpstan-param class-string<T> $class_name
* @phpstan-param array{screen?: string} $args
* @phpstan-return ($class_name is 'WP_Posts_List_Table'|'WP_Media_List_Table'|'WP_Terms_List_Table'|'WP_Users_List_Table'|'WP_Comments_List_Table'|'WP_Post_Comments_List_Table'|'WP_Links_List_Table'|'WP_Plugin_Install_List_Table'|'WP_Themes_List_Table'|'WP_Theme_Install_List_Table'|'WP_Plugins_List_Table'|'WP_Application_Passwords_List_Table'|'WP_MS_Sites_List_Table'|'WP_MS_Users_List_Table'|'WP_MS_Themes_List_Table'|'WP_Privacy_Data_Export_Requests_List_Table'|'WP_Privacy_Data_Removal_Requests_List_Table' ? \WP_List_Table : false)
* @phpstan-return ($class_name is 'WP_Posts_List_Table'|'WP_Media_List_Table'|'WP_Terms_List_Table'|'WP_Users_List_Table'|'WP_Comments_List_Table'|'WP_Post_Comments_List_Table'|'WP_Links_List_Table'|'WP_Plugin_Install_List_Table'|'WP_Themes_List_Table'|'WP_Theme_Install_List_Table'|'WP_Plugins_List_Table'|'WP_Application_Passwords_List_Table'|'WP_MS_Sites_List_Table'|'WP_MS_Users_List_Table'|'WP_MS_Themes_List_Table'|'WP_Privacy_Data_Export_Requests_List_Table'|'WP_Privacy_Data_Removal_Requests_List_Table' ? T : false)
*/
function _get_list_table($class_name, $args = array())
{
Expand Down