diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 9f5b87ce85f93..543d2c7f89766 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -1237,6 +1237,8 @@ function image_align_input_fields( $post, $checked = '' ) { * @param WP_Post $post * @param bool|string $check * @return array An array of data for the image size input fields. + * + * @phpstan-return array{label: string, input: 'html', html: string} */ function image_size_input_fields( $post, $check = '' ) { /** @@ -1937,6 +1939,8 @@ function get_media_item( $attachment_id, $args = null ) { * @param int $attachment_id * @param array $args * @return array An array containing the media item and its metadata. + * + * @phpstan-return array{item: string, meta: string} */ function get_compat_media_markup( $attachment_id, $args = null ) { $post = get_post( $attachment_id ); diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php index 8e3c141af2850..ff9fb830c4d2a 100644 --- a/src/wp-admin/includes/ms.php +++ b/src/wp-admin/includes/ms.php @@ -1187,6 +1187,8 @@ function network_edit_site_nav( $args = array() ) { * @since 4.9.0 * * @return array Help tab arguments. + * + * @phpstan-return array{id: non-falsy-string, title: string, content: non-falsy-string} */ function get_site_screen_help_tab_args() { return array( diff --git a/src/wp-admin/includes/nav-menu.php b/src/wp-admin/includes/nav-menu.php index dc90feb3b3309..68726f4062cde 100644 --- a/src/wp-admin/includes/nav-menu.php +++ b/src/wp-admin/includes/nav-menu.php @@ -1348,6 +1348,16 @@ function wp_get_nav_menu_to_edit( $menu_id = 0 ) { * @since 3.0.0 * * @return string[] Array of column titles keyed by their column name. + * + * @phpstan-return array{ + * _title: string, + * cb: non-falsy-string, + * link-target: string, + * title-attribute: string, + * css-classes: string, + * xfn: string, + * description: string, + * } */ function wp_nav_menu_manage_columns() { return array( diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index f08f81766df67..7d900970fd0cc 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -1220,6 +1220,8 @@ function _fix_attachment_links( $post ) { * * @param string $type The post_type you want the statuses for. Default 'post'. * @return string[] An array of all the statuses for the supplied post type. + * + * @phpstan-return list */ function get_available_post_statuses( $type = 'post' ) { $statuses = wp_count_posts( $type ); diff --git a/src/wp-includes/class-wp-dependencies.php b/src/wp-includes/class-wp-dependencies.php index f9aa688cca3af..204ade1d6f0f0 100644 --- a/src/wp-includes/class-wp-dependencies.php +++ b/src/wp-includes/class-wp-dependencies.php @@ -73,7 +73,9 @@ class WP_Dependencies { * * @since 2.8.0 * - * @var (int|false)[] + * @var array + * + * @phpstan-var array */ public $groups = array(); diff --git a/src/wp-includes/class-wp-http.php b/src/wp-includes/class-wp-http.php index 66cf907d0e00a..de53011d11983 100644 --- a/src/wp-includes/class-wp-http.php +++ b/src/wp-includes/class-wp-http.php @@ -29,6 +29,15 @@ * Debugging includes several actions, which pass different variables for debugging the HTTP API. * * @since 2.7.0 + * + * @phpstan-type HTTP_Response array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * } */ #[AllowDynamicProperties] class WP_Http { @@ -166,6 +175,8 @@ class WP_Http { * @type string|null $filename Optional. Filename of the response. * @type WP_HTTP_Requests_Response|null $http_response Response object. * } + * + * @phpstan-return HTTP_Response|WP_Error */ public function request( $url, $args = array() ) { $defaults = array( @@ -647,6 +658,8 @@ private function _dispatch_request( $url, $args ) { * @param string|array $args Optional. Override the defaults. * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. * A WP_Error instance upon error. See WP_Http::response() for details. + * + * @phpstan-return HTTP_Response|WP_Error */ public function post( $url, $args = array() ) { $defaults = array( 'method' => 'POST' ); @@ -665,6 +678,8 @@ public function post( $url, $args = array() ) { * @param string|array $args Optional. Override the defaults. * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. * A WP_Error instance upon error. See WP_Http::response() for details. + * + * @phpstan-return HTTP_Response|WP_Error */ public function get( $url, $args = array() ) { $defaults = array( 'method' => 'GET' ); @@ -683,6 +698,8 @@ public function get( $url, $args = array() ) { * @param string|array $args Optional. Override the defaults. * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. * A WP_Error instance upon error. See WP_Http::response() for details. + * + * @phpstan-return HTTP_Response|WP_Error */ public function head( $url, $args = array() ) { $defaults = array( 'method' => 'HEAD' ); diff --git a/src/wp-includes/class-wp-widget.php b/src/wp-includes/class-wp-widget.php index f1d432c0d3fb5..9cc2d79a7ac20 100644 --- a/src/wp-includes/class-wp-widget.php +++ b/src/wp-includes/class-wp-widget.php @@ -109,6 +109,22 @@ class WP_Widget { * @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. + * + * @phpstan-param array{ + * name?: string, + * id?: string, + * description?: string, + * class?: string, + * before_widget: string, + * after_widget: string, + * before_title: string, + * after_title: string, + * before_sidebar?: string, + * after_sidebar?: string, + * show_in_rest?: bool, + * widget_id?: string, + * widget_name?: string, + * } $args */ public function widget( $args, $instance ) { die( 'function WP_Widget::widget() must be overridden in a subclass.' ); diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php index 952194c1bce84..016d6a86b32f3 100644 --- a/src/wp-includes/feed.php +++ b/src/wp-includes/feed.php @@ -599,6 +599,8 @@ function atom_enclosure() { * * @param string $data Input string. * @return array array(type, value) + * + * @phpstan-return array{'html'|'text'|'xhtml', string} */ function prep_atom_text_construct( $data ) { if ( ! str_contains( $data, '<' ) && ! str_contains( $data, '&' ) ) { diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 14836be11db76..6bfba5a873cb7 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -611,6 +611,8 @@ function wpautop( $text, $br = true ) { * * @param string $input The text which has to be formatted. * @return string[] Array of the formatted text. + * + * @phpstan-return non-empty-list */ function wp_html_split( $input ) { return preg_split( get_html_split_regex(), $input, -1, PREG_SPLIT_DELIM_CAPTURE ); diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 693ba8c38859e..9f05a8c592a86 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -8394,6 +8394,7 @@ function wp_unique_prefixed_id( $prefix = '' ) { * @param string $prefix Optional. A prefix to prepend to the generated ID. Default empty string. * @return string The generated unique ID for the array. * + * @phpstan-param non-empty-array $data * @phpstan-return ( $prefix is lowercase-string ? lowercase-string&non-falsy-string : non-falsy-string ) */ function wp_unique_id_from_values( array $data, string $prefix = '' ): string { diff --git a/src/wp-includes/http.php b/src/wp-includes/http.php index 34e1f452a797f..ac589db1e91d3 100644 --- a/src/wp-includes/http.php +++ b/src/wp-includes/http.php @@ -48,6 +48,15 @@ function _wp_http_get_object() { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response or WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_safe_remote_request( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; @@ -77,6 +86,15 @@ function wp_safe_remote_request( $url, $args = array() ) { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response or WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_safe_remote_get( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; @@ -106,6 +124,15 @@ function wp_safe_remote_get( $url, $args = array() ) { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response or WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_safe_remote_post( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; @@ -135,6 +162,15 @@ function wp_safe_remote_post( $url, $args = array() ) { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response or WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_safe_remote_head( $url, $args = array() ) { $args['reject_unsafe_urls'] = true; @@ -162,6 +198,15 @@ function wp_safe_remote_head( $url, $args = array() ) { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response array or a WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_remote_request( $url, $args = array() ) { $http = _wp_http_get_object(); @@ -183,6 +228,15 @@ function wp_remote_request( $url, $args = array() ) { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response or WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_remote_get( $url, $args = array() ) { $http = _wp_http_get_object(); @@ -204,6 +258,15 @@ function wp_remote_get( $url, $args = array() ) { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response or WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_remote_post( $url, $args = array() ) { $http = _wp_http_get_object(); @@ -225,6 +288,15 @@ function wp_remote_post( $url, $args = array() ) { * See WP_Http::request() for information on accepted arguments. * @return array|WP_Error The response or WP_Error on failure. * See WP_Http::request() for information on return value. + * + * @phpstan-return array{ + * headers: \WpOrg\Requests\Utility\CaseInsensitiveDictionary|array, + * body: string, + * response: array{code: int|false, message: string|false}, + * cookies: WP_Http_Cookie[], + * filename?: string|null, + * http_response?: WP_HTTP_Requests_Response|null, + * }|WP_Error */ function wp_remote_head( $url, $args = array() ) { $http = _wp_http_get_object(); diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php index 191c8d06489c6..2420a2583c82d 100644 --- a/src/wp-includes/nav-menu.php +++ b/src/wp-includes/nav-menu.php @@ -85,7 +85,7 @@ function is_nav_menu( $menu ) { * * @global array $_wp_registered_nav_menus * - * @param string[] $locations Associative array of menu location identifiers (like a slug) and descriptive text. + * @param array $locations Associative array of menu location identifiers (like a slug) and descriptive text. */ function register_nav_menus( $locations = array() ) { global $_wp_registered_nav_menus; diff --git a/src/wp-includes/robots-template.php b/src/wp-includes/robots-template.php index e719e745d61e7..49216bfa7400e 100644 --- a/src/wp-includes/robots-template.php +++ b/src/wp-includes/robots-template.php @@ -64,8 +64,8 @@ function wp_robots() { * * @see wp_robots_no_robots() * - * @param array $robots Associative array of robots directives. - * @return array Filtered robots directives. + * @param array $robots Associative array of robots directives. + * @return array Filtered robots directives. */ function wp_robots_noindex( array $robots ) { if ( ! get_option( 'blog_public' ) ) { @@ -86,8 +86,8 @@ function wp_robots_noindex( array $robots ) { * * @see wp_robots_no_robots() * - * @param array $robots Associative array of robots directives. - * @return array Filtered robots directives. + * @param array $robots Associative array of robots directives. + * @return array Filtered robots directives. */ function wp_robots_noindex_embeds( array $robots ) { if ( is_embed() ) { @@ -112,8 +112,8 @@ function wp_robots_noindex_embeds( array $robots ) { * * @see wp_robots_no_robots() * - * @param array $robots Associative array of robots directives. - * @return array Filtered robots directives. + * @param array $robots Associative array of robots directives. + * @return array Filtered robots directives. */ function wp_robots_noindex_search( array $robots ) { if ( is_search() ) { @@ -134,8 +134,10 @@ function wp_robots_noindex_search( array $robots ) { * * @since 5.7.0 * - * @param array $robots Associative array of robots directives. - * @return array Filtered robots directives. + * @param array $robots Associative array of robots directives. + * @return array Filtered robots directives. + * + * @phpstan-return array{ noindex: true, ... } */ function wp_robots_no_robots( array $robots ) { $robots['noindex'] = true; @@ -161,8 +163,10 @@ function wp_robots_no_robots( array $robots ) { * * @since 5.7.0 * - * @param array $robots Associative array of robots directives. - * @return array Filtered robots directives. + * @param array $robots Associative array of robots directives. + * @return array Filtered robots directives. + * + * @phpstan-return array{ noindex: true, noarchive: true, ... } */ function wp_robots_sensitive_page( array $robots ) { $robots['noindex'] = true; @@ -182,8 +186,8 @@ function wp_robots_sensitive_page( array $robots ) { * * @since 5.7.0 * - * @param array $robots Associative array of robots directives. - * @return array Filtered robots directives. + * @param array $robots Associative array of robots directives. + * @return array Filtered robots directives. */ function wp_robots_max_image_preview_large( array $robots ) { if ( get_option( 'blog_public' ) ) { diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php index bc946676bd81c..32429b871d668 100644 --- a/src/wp-includes/shortcodes.php +++ b/src/wp-includes/shortcodes.php @@ -188,6 +188,8 @@ function has_shortcode( $content, $tag ) { * * @param string $content The content to check. * @return string[] An array of registered shortcode names found in the content. + * + * @phpstan-return list */ function get_shortcode_tags_in_content( $content ) { if ( ! str_contains( $content, '[' ) ) { diff --git a/src/wp-includes/widgets.php b/src/wp-includes/widgets.php index 31fce41b65954..b6d9c018851f3 100644 --- a/src/wp-includes/widgets.php +++ b/src/wp-includes/widgets.php @@ -1717,6 +1717,25 @@ function wp_widget_rss_output( $rss, $args = array() ) { * * @param array|string $args Values for input fields. * @param array $inputs Override default display options. + * + * @phpstan-param array{ + * number: int|string, + * error?: string|false, + * title?: string, + * url?: string, + * items?: int, + * show_summary?: int, + * show_author?: int, + * show_date?: int, + * } $args + * @phpstan-param array{ + * title?: bool|'hidden', + * url?: bool|'hidden', + * items?: bool|'hidden', + * show_summary?: bool|'hidden', + * show_author?: bool|'hidden', + * show_date?: bool|'hidden', + * } $inputs */ function wp_widget_rss_form( $args, $inputs = null ) { $default_inputs = array( @@ -1802,6 +1821,17 @@ function wp_widget_rss_form( $args, $inputs = null ) { * @param array $widget_rss RSS widget feed data. Expects unescaped data. * @param bool $check_feed Optional. Whether to check feed for errors. Default true. * @return array + * + * @phpstan-return array{ + * title: string, + * url: string, + * link: string, + * items: int<1, 20>, + * error: string|false, + * show_summary: int, + * show_author: int, + * show_date: int, + * } */ function wp_widget_rss_process( $widget_rss, $check_feed = true ) { $items = (int) $widget_rss['items']; diff --git a/tests/phpstan/baselines-strict/argument.type.neon b/tests/phpstan/baselines-strict/argument.type.neon index dd83b950de430..967bf80d53e61 100644 --- a/tests/phpstan/baselines-strict/argument.type.neon +++ b/tests/phpstan/baselines-strict/argument.type.neon @@ -33,11 +33,6 @@ parameters: identifier: argument.type count: 1 path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php - - - message: '#^Parameter \#1 \$wp_response of method WP_AI_Client_HTTP_Client\:\:create_psr_response\(\) expects array\, array given\.$#' - identifier: argument.type - count: 2 - path: ../../../src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php - message: '#^Parameter \#2 \$value of method WordPress\\AiClientDependencies\\Psr\\Http\\Message\\MessageInterface\:\:withHeader\(\) expects array\\|string, mixed given\.$#' identifier: argument.type