diff --git a/src/wp-includes/class-walker-nav-menu.php b/src/wp-includes/class-walker-nav-menu.php index 1f9bd6bfdd536..f462ad772ab7c 100644 --- a/src/wp-includes/class-walker-nav-menu.php +++ b/src/wp-includes/class-walker-nav-menu.php @@ -19,7 +19,7 @@ class Walker_Nav_Menu extends Walker { * What the class handles. * * @since 3.0.0 - * @var string + * @var string[] * * @see Walker::$tree_type */ diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index 8baf0f99bacde..199eba4f41c82 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -68,8 +68,10 @@ class WP_Block { /** * List of inner blocks (of this same class) * + * This is an empty array when the block has no inner blocks. + * * @since 5.5.0 - * @var WP_Block_List + * @var WP_Block_List|array{} */ public $inner_blocks = array(); diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index ad706ba532114..c1a77ee591e45 100644 --- a/src/wp-includes/class-wp-comment-query.php +++ b/src/wp-includes/class-wp-comment-query.php @@ -28,8 +28,10 @@ class WP_Comment_Query { /** * Metadata query container * + * This is false until the query is run. + * * @since 3.5.0 - * @var WP_Meta_Query A meta query instance. + * @var WP_Meta_Query|false A meta query instance. */ public $meta_query = false; @@ -69,8 +71,10 @@ class WP_Comment_Query { /** * Date query container * + * This is false unless the query has a `date_query` argument. + * * @since 3.7.0 - * @var WP_Date_Query A date query instance. + * @var WP_Date_Query|false A date query instance. */ public $date_query = false; diff --git a/src/wp-includes/class-wp-customize-control.php b/src/wp-includes/class-wp-customize-control.php index 859958a2f6838..45cff6b38064c 100644 --- a/src/wp-includes/class-wp-customize-control.php +++ b/src/wp-includes/class-wp-customize-control.php @@ -157,14 +157,18 @@ class WP_Customize_Control { /** * Callback. * + * This is an empty string by default, which the constructor replaces with + * WP_Customize_Control::active_callback(). + * * @since 4.0.0 * * @see WP_Customize_Control::active() * - * @var callable Callback is called with one argument, the instance of - * WP_Customize_Control, and returns bool to indicate whether - * the control is active (such as it relates to the URL - * currently being previewed). + * @var callable|string Callback is called with one argument, the instance of + * WP_Customize_Control, and returns bool to indicate whether + * the control is active (such as it relates to the URL + * currently being previewed). + * @phpstan-var callable|'' */ public $active_callback = ''; diff --git a/src/wp-includes/class-wp-customize-panel.php b/src/wp-includes/class-wp-customize-panel.php index 9607358bd220b..9a72956874ad0 100644 --- a/src/wp-includes/class-wp-customize-panel.php +++ b/src/wp-includes/class-wp-customize-panel.php @@ -78,7 +78,7 @@ class WP_Customize_Panel { * Theme features required to support the panel. * * @since 4.0.0 - * @var mixed[] + * @var string|string[] */ public $theme_supports = ''; @@ -125,14 +125,18 @@ class WP_Customize_Panel { /** * Active callback. * + * This is an empty string by default, which the constructor replaces with + * WP_Customize_Panel::active_callback(). + * * @since 4.1.0 * - * @see WP_Customize_Section::active() + * @see WP_Customize_Panel::active() * - * @var callable Callback is called with one argument, the instance of - * WP_Customize_Section, and returns bool to indicate whether - * the section is active (such as it relates to the URL currently - * being previewed). + * @var callable|string Callback is called with one argument, the instance of + * WP_Customize_Panel, and returns bool to indicate whether + * the panel is active (such as it relates to the URL currently + * being previewed). + * @phpstan-var callable|'' */ public $active_callback = ''; @@ -152,7 +156,7 @@ class WP_Customize_Panel { * of panels and sections. Default 160. * @type string $capability Capability required for the panel. * Default `edit_theme_options`. - * @type mixed[] $theme_supports Theme features required to support the panel. + * @type string|string[] $theme_supports Theme features required to support the panel. * @type string $title Title of the panel to show in UI. * @type string $description Description to show in the UI. * @type string $type Type of the panel. diff --git a/src/wp-includes/class-wp-customize-section.php b/src/wp-includes/class-wp-customize-section.php index d2ef51ab0c57f..7d463c0ee76dc 100644 --- a/src/wp-includes/class-wp-customize-section.php +++ b/src/wp-includes/class-wp-customize-section.php @@ -120,14 +120,18 @@ class WP_Customize_Section { /** * Active callback. * + * This is an empty string by default, which the constructor replaces with + * WP_Customize_Section::active_callback(). + * * @since 4.1.0 * * @see WP_Customize_Section::active() * - * @var callable Callback is called with one argument, the instance of - * WP_Customize_Section, and returns bool to indicate whether - * the section is active (such as it relates to the URL currently - * being previewed). + * @var callable|string Callback is called with one argument, the instance of + * WP_Customize_Section, and returns bool to indicate whether + * the section is active (such as it relates to the URL currently + * being previewed). + * @phpstan-var callable|'' */ public $active_callback = ''; diff --git a/src/wp-includes/class-wp-customize-setting.php b/src/wp-includes/class-wp-customize-setting.php index 77a544bfbae0e..89d6322dbdc13 100644 --- a/src/wp-includes/class-wp-customize-setting.php +++ b/src/wp-includes/class-wp-customize-setting.php @@ -86,24 +86,33 @@ class WP_Customize_Setting { /** * Server-side validation callback for the setting's value. * + * An empty string means there is no callback. + * * @since 4.6.0 - * @var callable + * @var callable|string + * @phpstan-var callable|'' */ public $validate_callback = ''; /** * Callback to filter a Customize setting value in un-slashed form. * + * An empty string means there is no callback. + * * @since 3.4.0 - * @var callable + * @var callable|string + * @phpstan-var callable|'' */ public $sanitize_callback = ''; /** * Callback to convert a Customize PHP setting value to a value that is JSON serializable. * + * An empty string means there is no callback. + * * @since 3.4.0 - * @var callable + * @var callable|string + * @phpstan-var callable|'' */ public $sanitize_js_callback = ''; diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 0c07cb26bf71d..913738319c769 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -49,16 +49,20 @@ class WP_Query { /** * Metadata query container. * + * This is false until the query is run. + * * @since 3.2.0 - * @var WP_Meta_Query A meta query instance. + * @var WP_Meta_Query|false A meta query instance. */ public $meta_query = false; /** * Date query container. * + * This is false unless the query has a `date_query` argument. + * * @since 3.7.0 - * @var WP_Date_Query A date query instance. + * @var WP_Date_Query|false A date query instance. */ public $date_query = false; diff --git a/src/wp-includes/class-wp-site-query.php b/src/wp-includes/class-wp-site-query.php index aab8b511fcf83..b2e90f7d9812b 100644 --- a/src/wp-includes/class-wp-site-query.php +++ b/src/wp-includes/class-wp-site-query.php @@ -43,8 +43,10 @@ class WP_Site_Query { /** * Metadata query container. * + * This is false until the query is run. + * * @since 5.1.0 - * @var WP_Meta_Query + * @var WP_Meta_Query|false */ public $meta_query = false; @@ -59,8 +61,10 @@ class WP_Site_Query { /** * Date query container. * + * This is false unless the query has a `date_query` argument. + * * @since 4.6.0 - * @var WP_Date_Query A date query instance. + * @var WP_Date_Query|false A date query instance. */ public $date_query = false; diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 179a8decd7e55..13e768c52de87 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -29,8 +29,10 @@ class WP_Term_Query { /** * Metadata query container. * + * This is false until the query is run. + * * @since 4.6.0 - * @var WP_Meta_Query A meta query instance. + * @var WP_Meta_Query|false A meta query instance. */ public $meta_query = false; diff --git a/src/wp-includes/class-wp-term.php b/src/wp-includes/class-wp-term.php index a9a58da875e4a..e34fc1a93d067 100644 --- a/src/wp-includes/class-wp-term.php +++ b/src/wp-includes/class-wp-term.php @@ -47,7 +47,7 @@ final class WP_Term { * @since 4.4.0 * @var int */ - public $term_group = ''; + public $term_group = 0; /** * Term Taxonomy ID. diff --git a/src/wp-includes/class-wp-user-query.php b/src/wp-includes/class-wp-user-query.php index 61fc3edbc8ef9..27990ea6dcff9 100644 --- a/src/wp-includes/class-wp-user-query.php +++ b/src/wp-includes/class-wp-user-query.php @@ -44,8 +44,10 @@ class WP_User_Query { /** * Metadata query container. * + * This is false until the query is run. + * * @since 4.2.0 - * @var WP_Meta_Query + * @var WP_Meta_Query|false */ public $meta_query = false; diff --git a/src/wp-includes/class-wp-walker.php b/src/wp-includes/class-wp-walker.php index 2c40984119165..068ac4c7451ad 100644 --- a/src/wp-includes/class-wp-walker.php +++ b/src/wp-includes/class-wp-walker.php @@ -17,7 +17,7 @@ class Walker { * What the class handles. * * @since 2.1.0 - * @var string + * @var string|string[] */ public $tree_type; diff --git a/tests/phpstan/baselines/empty.property.neon b/tests/phpstan/baselines/empty.property.neon index 29c45b3128ea4..9040ec4efd952 100644 --- a/tests/phpstan/baselines/empty.property.neon +++ b/tests/phpstan/baselines/empty.property.neon @@ -23,11 +23,6 @@ parameters: identifier: empty.property count: 1 path: ../../../src/wp-includes/blocks.php - - - message: '#^Property WP_Customize_Control\:\:\$active_callback \(callable\) in empty\(\) is not falsy\.$#' - identifier: empty.property - count: 1 - path: ../../../src/wp-includes/class-wp-customize-control.php - message: '#^Property WP_Customize_Manager\:\:\$nav_menus \(WP_Customize_Nav_Menus\) in empty\(\) is not falsy\.$#' identifier: empty.property @@ -38,16 +33,6 @@ parameters: identifier: empty.property count: 1 path: ../../../src/wp-includes/class-wp-customize-manager.php - - - message: '#^Property WP_Customize_Panel\:\:\$active_callback \(callable\) in empty\(\) is not falsy\.$#' - identifier: empty.property - count: 1 - path: ../../../src/wp-includes/class-wp-customize-panel.php - - - message: '#^Property WP_Customize_Section\:\:\$active_callback \(callable\) in empty\(\) is not falsy\.$#' - identifier: empty.property - count: 1 - path: ../../../src/wp-includes/class-wp-customize-section.php - message: '#^Property WP_Customize_Manager\:\:\$nav_menus \(WP_Customize_Nav_Menus\) in empty\(\) is not falsy\.$#' identifier: empty.property diff --git a/tests/phpstan/baselines/property.defaultValue.neon b/tests/phpstan/baselines/property.defaultValue.neon deleted file mode 100644 index 5c7ebe5274920..0000000000000 --- a/tests/phpstan/baselines/property.defaultValue.neon +++ /dev/null @@ -1,110 +0,0 @@ -# PHPStan baseline for the `property.defaultValue` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/property.defaultValue -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand. Regenerate with: -# -# composer phpstan:baselines -- --identifier=property.defaultValue --config=phpstan.neon.dist -# -# This reruns the analysis with the baselines in this directory suppressed, so -# that their errors surface again, and rewrites only this file. - -parameters: - ignoreErrors: - - - message: '#^Property Walker_Nav_Menu\:\:\$tree_type \(string\) does not accept default value of type array\\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-walker-nav-menu.php - - - message: '#^Property WP_Block\:\:\$inner_blocks \(WP_Block_List\) does not accept default value of type array\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-block.php - - - message: '#^Property WP_Comment_Query\:\:\$date_query \(WP_Date_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-comment-query.php - - - message: '#^Property WP_Comment_Query\:\:\$meta_query \(WP_Meta_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-comment-query.php - - - message: '#^Property WP_Customize_Control\:\:\$active_callback \(callable\(\)\: mixed\) does not accept default value of type ''''\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-customize-control.php - - - message: '#^Property WP_Customize_Panel\:\:\$active_callback \(callable\(\)\: mixed\) does not accept default value of type ''''\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-customize-panel.php - - - message: '#^Property WP_Customize_Panel\:\:\$theme_supports \(array\\) does not accept default value of type string\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-customize-panel.php - - - message: '#^Property WP_Customize_Section\:\:\$active_callback \(callable\(\)\: mixed\) does not accept default value of type ''''\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-customize-section.php - - - message: '#^Property WP_Customize_Setting\:\:\$sanitize_callback \(callable\(\)\: mixed\) does not accept default value of type ''''\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-customize-setting.php - - - message: '#^Property WP_Customize_Setting\:\:\$sanitize_js_callback \(callable\(\)\: mixed\) does not accept default value of type ''''\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-customize-setting.php - - - message: '#^Property WP_Customize_Setting\:\:\$validate_callback \(callable\(\)\: mixed\) does not accept default value of type ''''\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-customize-setting.php - - - message: '#^Property WP_Query\:\:\$date_query \(WP_Date_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-query.php - - - message: '#^Property WP_Query\:\:\$meta_query \(WP_Meta_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-query.php - - - message: '#^Property WP_Site_Query\:\:\$date_query \(WP_Date_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-site-query.php - - - message: '#^Property WP_Site_Query\:\:\$meta_query \(WP_Meta_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-site-query.php - - - message: '#^Property WP_Term_Query\:\:\$meta_query \(WP_Meta_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-term-query.php - - - message: '#^Property WP_Term\:\:\$term_group \(int\) does not accept default value of type string\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-term.php - - - message: '#^Property WP_User_Query\:\:\$meta_query \(WP_Meta_Query\) does not accept default value of type false\.$#' - identifier: property.defaultValue - count: 1 - path: ../../../src/wp-includes/class-wp-user-query.php diff --git a/tests/phpunit/tests/term/wpTerm.php b/tests/phpunit/tests/term/wpTerm.php index 0eda866356514..9a6e3c7905f90 100644 --- a/tests/phpunit/tests/term/wpTerm.php +++ b/tests/phpunit/tests/term/wpTerm.php @@ -187,4 +187,34 @@ public static function data_get_instance_treats_a_poisoned_cache_value_as_a_cach 'a WP_Term without term_id' => array( new WP_Term( new stdClass() ) ), ); } + + /** + * Tests that `term_group` defaults to the integer 0 when the term data does not include it. + * + * @ticket 66739 + * + * @covers WP_Term::__construct + * + * @dataProvider data_term_group + * + * @param object $data Term data passed to the constructor. + * @param int $expected Expected term group. + */ + public function test_term_group( object $data, int $expected ): void { + $term = new WP_Term( $data ); + + $this->assertSame( $expected, $term->term_group ); + } + + /** + * Data provider. + * + * @return array + */ + public static function data_term_group(): array { + return array( + 'term data without term_group' => array( new stdClass(), 0 ), + 'term data with a term_group' => array( (object) array( 'term_group' => 2 ), 2 ), + ); + } }