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

Add support for dynamic return type in WP_List_Table methods #181

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
'WP_Http::head' => [$httpReturnType],
'WP_Http::post' => [$httpReturnType],
'WP_Http::request' => [$httpReturnType],
'WP_List_Table' => [null, '@phpstan-template' => 'T of array<string, float|int|string>|object', '@template' => 'K of string'],
'WP_List_Table::get_columns' => ['array<K, string>'],
'WP_List_Table::get_sortable_columns' => ['array<K, string>'],
'WP_List_Table::get_default_primary_column_name' => ['K'],
'WP_List_Table::get_primary_column' => [ 'K'],
'WP_List_Table::get_primary_column_name' => [ 'K'],
'WP_List_Table::single_row' => [null, 'item' => 'T'],
'WP_List_Table::column_default' => [null, 'item' => 'T', 'column_name' => 'K'],
'WP_List_Table::column_cb' => [null, 'item' => 'T'],
'WP_List_Table::single_row_columns' => [null, 'item' => 'T'],
'WP_List_Table::handle_row_actions' => [null, 'item' => 'T', 'column_name' => 'K', 'primary' => 'key-of<T>'],
'WP_List_Table::set_pagination_args' => ['void', 'args' => 'array{total_items?: int, total_pages?: int, per_page?: int}'],
'wp_next_scheduled' => [null, 'args' => $cronArgsType],
'WP_Query::have_posts' => [null, '@phpstan-impure' => ''],
Expand Down
15 changes: 15 additions & 0 deletions wordpress-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4162,6 +4162,8 @@ public function feedback($feedback, ...$args)
* Base class for displaying a list of items in an ajaxified HTML table.
*
* @since 3.1.0
* @phpstan-template T of array<string, float|int|string>|object
* @template K of string
*/
#[\AllowDynamicProperties]
class WP_List_Table
Expand Down Expand Up @@ -4577,6 +4579,7 @@ protected function pagination($which)
* @abstract
*
* @return array
* @phpstan-return array<K, string>
*/
public function get_columns()
{
Expand All @@ -4599,6 +4602,7 @@ public function get_columns()
* @since 6.3.0 Added 'abbr', 'orderby-text' and 'initially-sorted-column-order'.
*
* @return array
* @phpstan-return array<K, string>
*/
protected function get_sortable_columns()
{
Expand All @@ -4609,6 +4613,7 @@ protected function get_sortable_columns()
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, an empty string.
* @phpstan-return K
*/
protected function get_default_primary_column_name()
{
Expand All @@ -4621,6 +4626,7 @@ protected function get_default_primary_column_name()
* @since 4.4.0
*
* @return string Name of the default primary column.
* @phpstan-return K
*/
public function get_primary_column()
{
Expand All @@ -4631,6 +4637,7 @@ public function get_primary_column()
* @since 4.3.0
*
* @return string The name of the primary column.
* @phpstan-return K
*/
protected function get_primary_column_name()
{
Expand Down Expand Up @@ -4738,19 +4745,23 @@ public function display_rows()
* @since 3.1.0
*
* @param object|array $item The current item
* @phpstan-param T $item
*/
public function single_row($item)
{
}
/**
* @param object|array $item
* @param string $column_name
* @phpstan-param T $item
* @phpstan-param K $column_name
*/
protected function column_default($item, $column_name)
{
}
/**
* @param object|array $item
* @phpstan-param T $item
*/
protected function column_cb($item)
{
Expand All @@ -4761,6 +4772,7 @@ protected function column_cb($item)
* @since 3.1.0
*
* @param object|array $item The current item.
* @phpstan-param T $item
*/
protected function single_row_columns($item)
{
Expand All @@ -4775,6 +4787,9 @@ protected function single_row_columns($item)
* @param string $primary Primary column name.
* @return string The row actions HTML, or an empty string
* if the current column is not the primary column.
* @phpstan-param T $item
* @phpstan-param K $column_name
* @phpstan-param key-of<T> $primary
*/
protected function handle_row_actions($item, $column_name, $primary)
{
Expand Down