Skip to content
Closed
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
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ includes:
- tests/phpstan/baselines/isset.offset.neon
- tests/phpstan/baselines/isset.property.neon
- tests/phpstan/baselines/method.childParameterType.neon
- tests/phpstan/baselines/method.nonObject.neon
- tests/phpstan/baselines/method.unused.neon
- tests/phpstan/baselines/notIdentical.alwaysTrue.neon
- tests/phpstan/baselines/nullCoalesce.offset.neon
Expand Down
24 changes: 12 additions & 12 deletions src/wp-admin/includes/class-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,18 @@ class WP_List_Table {
* @param array|string $args {
* Array or string of arguments.
*
* @type string $plural Plural value used for labels and the objects being listed.
* This affects things such as CSS class-names and nonces used
* in the list table, e.g. 'posts'. Default empty.
* @type string $singular Singular label for an object being listed, e.g. 'post'.
* Default empty
* @type bool $ajax Whether the list table supports Ajax. This includes loading
* and sorting data, for example. If true, the class will call
* the _js_vars() method in the footer to provide variables
* to any scripts handling Ajax events. Default false.
* @type string $screen String containing the hook name used to determine the current
* screen. If left null, the current screen will be automatically set.
* Default null.
* @type string $plural Plural value used for labels and the objects being listed.
* This affects things such as CSS class-names and nonces used
* in the list table, e.g. 'posts'. Default empty.
* @type string $singular Singular label for an object being listed, e.g. 'post'.
* Default empty.
* @type bool $ajax Whether the list table supports Ajax. This includes loading
* and sorting data, for example. If true, the class will call
* the _js_vars() method in the footer to provide variables
* to any scripts handling Ajax events. Default false.
* @type string|WP_Screen|null $screen String containing the hook name used to determine the current
* screen, or a `WP_Screen` instance. If left null, the current
* screen will be automatically set. Default null.
* }
*/
public function __construct( $args = array() ) {
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/class-wp-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ final class WP_Screen {
*
* @global string $hook_suffix
*
* @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
* Defaults to the current $hook_suffix global.
* @param string|WP_Screen|null $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
* Defaults to the current $hook_suffix global.
* @return WP_Screen Screen object.
*/
public static function get( $hook_name = '' ) {
Expand Down
27 changes: 25 additions & 2 deletions src/wp-admin/includes/list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,28 @@
* @global string $hook_suffix
*
* @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.
* @param array $args {
* Optional. Arguments to pass to the class.
*
* @type string $plural Plural value used for labels and the objects being listed.
* This affects things such as CSS class-names and nonces used
* in the list table, e.g. 'posts'. Default empty.
* @type string $singular Singular label for an object being listed, e.g. 'post'.
* Default empty.
* @type bool $ajax Whether the list table supports Ajax. This includes loading
* and sorting data, for example. If true, the class will call
* the _js_vars() method in the footer to provide variables
* to any scripts handling Ajax events. Default false.
* @type string|WP_Screen|null $screen String containing the hook name used to determine the current
* screen, or a `WP_Screen` instance. If left null, the current
* screen will be automatically set. Default null.
* }
* @return WP_List_Table|false List table object of the type given in `$class_name`
* on success, false if the class does not exist.
*
* @phpstan-template T of WP_List_Table
* @phpstan-param class-string<T> $class_name
* @phpstan-return T|false
*/
function _get_list_table( $class_name, $args = array() ) {
$core_classes = array(
Expand Down Expand Up @@ -64,6 +84,9 @@ function _get_list_table( $class_name, $args = array() ) {
*
* @param string $class_name The list table class to use.
* @param array $args An array containing _get_list_table() arguments.
*
* @phpstan-template T of WP_List_Table
* @phpstan-param class-string<T> $class_name
Comment on lines +87 to +89

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the following PHPStan error:

Function _get_list_table() should return (T of WP_List_Table)|false but returns object.

*/
$custom_class_name = apply_filters( 'wp_list_table_class_name', $class_name, $args );

Expand Down
4 changes: 3 additions & 1 deletion src/wp-admin/includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,9 @@ function _wp_admin_html_begin() {
*
* @since 3.0.0
*
* @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
* @param string|WP_Screen|null $hook_name The hook name (also known as the hook suffix) used to determine the screen.
* A `WP_Screen` instance is returned as-is. If null, the current
* $hook_suffix global is used.
* @return WP_Screen Screen object.
*/
function convert_to_screen( $hook_name ) {
Expand Down
20 changes: 0 additions & 20 deletions tests/phpstan/baselines/arguments.count.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@

parameters:
ignoreErrors:
-
message: '#^Method WP_List_Table\:\:display_rows\(\) invoked with 2 parameters, 0 required\.$#'
identifier: arguments.count
count: 1
path: ../../../src/wp-admin/includes/ajax-actions.php
-
message: '#^Method WP_List_Table\:\:single_row\(\) invoked with 2 parameters, 1 required\.$#'
identifier: arguments.count
count: 2
path: ../../../src/wp-admin/includes/ajax-actions.php
-
message: '#^Method WP_List_Table\:\:single_row\(\) invoked with 3 parameters, 1 required\.$#'
identifier: arguments.count
count: 1
path: ../../../src/wp-admin/includes/ajax-actions.php
-
message: '#^Method WP_Upgrader_Skin\:\:before\(\) invoked with 1 parameter, 0 required\.$#'
identifier: arguments.count
Expand All @@ -43,8 +28,3 @@ parameters:
identifier: arguments.count
count: 2
path: ../../../src/wp-admin/includes/class-theme-upgrader.php
-
message: '#^Method WP_List_Table\:\:display\(\) invoked with 1 parameter, 0 required\.$#'
identifier: arguments.count
count: 1
path: ../../../src/wp-admin/includes/meta-boxes.php
55 changes: 0 additions & 55 deletions tests/phpstan/baselines/method.nonObject.neon

This file was deleted.

6 changes: 3 additions & 3 deletions tests/phpstan/baselines/property.protected.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
parameters:
ignoreErrors:
-
message: '#^Access to protected property WP_List_Table\:\:\$screen\.$#'
message: '#^Access to protected property WP_Privacy_Data_Removal_Requests_List_Table\:\:\$screen\.$#'
identifier: property.protected
count: 1
path: ../../../src/wp-admin/erase-personal-data.php
-
message: '#^Access to protected property WP_List_Table\:\:\$screen\.$#'
message: '#^Access to protected property WP_Privacy_Data_Export_Requests_List_Table\:\:\$screen\.$#'
identifier: property.protected
count: 1
path: ../../../src/wp-admin/export-personal-data.php
-
message: '#^Access to protected property WP_List_Table\:\:\$screen\.$#'
message: '#^Access to protected property WP_Posts_List_Table\:\:\$screen\.$#'
identifier: property.protected
count: 1
path: ../../../src/wp-admin/includes/ajax-actions.php
Expand Down
Loading