Skip to content
Open
6 changes: 6 additions & 0 deletions src/wp-includes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ function cat_is_ancestor_of( $cat1, $cat2 ) {
* @param object|array $category Category data.
* @param string $context Optional. Default 'display'.
* @return object|array Same type as $category with sanitized data for safe use.
*
* @phpstan-return (
* $category is WP_Term ? WP_Term : (
* $category is array ? array<string, mixed> : object
* )
* )
*/
function sanitize_category( $category, $context = 'display' ) {
return sanitize_term( $category, 'category', $context );
Expand Down
5 changes: 5 additions & 0 deletions src/wp-includes/class-wp-widget-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ public function WP_Widget_Factory() {
* @since 7.1.1 The key for an instance is prefixed so that it is never cast to an integer.
*
* @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass.
*
* @phpstan-param class-string<WP_Widget>|WP_Widget $widget
*/
public function register( $widget ) {
if ( $widget instanceof WP_Widget ) {
$this->widgets[ self::INSTANCE_KEY_PREFIX . spl_object_id( $widget ) ] = $widget;
} else {
// @phpstan-ignore arguments.count (Widget classes declare their own constructor, which takes no arguments.)
$this->widgets[ $widget ] = new $widget();
}
}
Expand All @@ -87,6 +90,8 @@ public function register( $widget ) {
* @since 7.1.1 The key for an instance is prefixed so that it is never cast to an integer.
*
* @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass.
*
* @phpstan-param class-string<WP_Widget>|WP_Widget $widget
*/
public function unregister( $widget ) {
if ( $widget instanceof WP_Widget ) {
Expand Down
16 changes: 8 additions & 8 deletions src/wp-includes/class-wp-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class WP_Widget {
*
* @since 2.8.0
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance The settings for the particular instance of the widget.
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array<string, mixed> $instance The settings for the particular instance of the widget.
*
* @phpstan-param array{
* name?: string,
Expand Down Expand Up @@ -139,10 +139,10 @@ public function widget( $args, $instance ) {
*
* @since 2.8.0
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
* @param array<string, mixed> $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array<string, mixed> $old_instance Old settings for this instance.
* @return array<string, mixed>|false Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
return $new_instance;
Expand All @@ -153,7 +153,7 @@ public function update( $new_instance, $old_instance ) {
*
* @since 2.8.0
*
* @param array $instance The settings for the particular instance of the widget.
* @param array<string, mixed> $instance The settings for the particular instance of the widget.
* @return string|void Default return is 'noform'. A subclass which echoes its own
* form returns nothing.
*/
Expand Down
24 changes: 18 additions & 6 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2943,8 +2943,12 @@ function stripslashes_from_strings_only( $value ) {
*
* @since 2.2.0
*
* @param mixed $value The array or string to be encoded.
* @return mixed The encoded value.
* @param mixed[]|object|scalar $value The array, object, or scalar to be encoded.
* @return mixed[]|object|string The encoded value.
*
* @phpstan-template T of mixed[]|object|scalar
* @phpstan-param T $value
* @phpstan-return (T is array ? array<key-of<T>, mixed> : (T is object ? T : string))

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.

Is the string branch proven? I see map_deep() uses mixed in the same spot. Perhaps $value should be narrowed from mixed to mixed[]|object|string?

Same goes for the following.

*/
function urlencode_deep( $value ) {
return map_deep( $value, 'urlencode' );
Expand All @@ -2955,8 +2959,12 @@ function urlencode_deep( $value ) {
*
* @since 3.4.0
*
* @param mixed $value The array or string to be encoded.
* @return mixed The encoded value.
* @param mixed[]|object|scalar $value The array, object, or scalar to be encoded.
* @return mixed[]|object|string The encoded value.
*
* @phpstan-template T of mixed[]|object|scalar
* @phpstan-param T $value
* @phpstan-return (T is array ? array<key-of<T>, mixed> : (T is object ? T : string))
*/
function rawurlencode_deep( $value ) {
return map_deep( $value, 'rawurlencode' );
Expand All @@ -2967,8 +2975,12 @@ function rawurlencode_deep( $value ) {
*
* @since 4.4.0
*
* @param mixed $value The array or string to be decoded.
* @return mixed The decoded value.
* @param mixed[]|object|scalar $value The array, object, or scalar to be decoded.
* @return mixed[]|object|string The decoded value.
*
* @phpstan-template T of mixed[]|object|scalar
* @phpstan-param T $value
* @phpstan-return (T is array ? array<key-of<T>, mixed> : (T is object ? T : string))
*/
function urldecode_deep( $value ) {
return map_deep( $value, 'urldecode' );
Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
* @global WP_Widget_Factory $wp_widget_factory
*
* @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass.
*
* @phpstan-param class-string<WP_Widget>|WP_Widget $widget
Comment thread
swissspidy marked this conversation as resolved.
Resolved
*/
function register_widget( $widget ) {
global $wp_widget_factory;
Expand All @@ -138,6 +140,8 @@ function register_widget( $widget ) {
* @global WP_Widget_Factory $wp_widget_factory
*
* @param string|WP_Widget $widget Either the name of a `WP_Widget` subclass or an instance of a `WP_Widget` subclass.
*
* @phpstan-param class-string<WP_Widget>|WP_Widget $widget
*/
function unregister_widget( $widget ) {
global $wp_widget_factory;
Expand Down
Loading