diff --git a/src/wp-includes/class-wp-post.php b/src/wp-includes/class-wp-post.php index d420c93fdce94..e1ed87885b41e 100644 --- a/src/wp-includes/class-wp-post.php +++ b/src/wp-includes/class-wp-post.php @@ -388,9 +388,11 @@ public function filter( $filter ) { * @since 3.5.0 * * @return array Object as array. + * + * @phpstan-return non-empty-array */ public function to_array() { - /** @var array $post */ + /** @var non-empty-array $post */ $post = get_object_vars( $this ); foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) { diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index a1d887b45381f..e26a3a6276e54 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -990,8 +990,8 @@ function _wp_relative_upload_path( $path ) { * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output * @phpstan-return ( * $args is array{ fields: 'ids', ... } ? int[] : ( - * $output is 'ARRAY_A' ? array> : ( - * $output is 'ARRAY_N' ? array> : WP_Post[] + * $output is 'ARRAY_A' ? array> : ( + * $output is 'ARRAY_N' ? array> : WP_Post[] * ) * ) * ) @@ -1040,13 +1040,17 @@ function get_children( $args = '', $output = OBJECT ) { } elseif ( ARRAY_A === $output ) { $weeuns = array(); foreach ( (array) $kids as $kid ) { - $weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] ); + /** @var non-empty-array $vars */ + $vars = get_object_vars( $kids[ $kid->ID ] ); + $weeuns[ $kid->ID ] = $vars; } return $weeuns; } elseif ( ARRAY_N === $output ) { $babes = array(); foreach ( (array) $kids as $kid ) { - $babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) ); + /** @var non-empty-array $vars */ + $vars = get_object_vars( $kids[ $kid->ID ] ); + $babes[ $kid->ID ] = array_values( $vars ); } return $babes; } else { @@ -1124,8 +1128,8 @@ function get_extended( $post ) { * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output * @phpstan-param 'raw'|'edit'|'db'|'display' $filter * @phpstan-return ( - * $output is 'ARRAY_A' ? array|null : ( - * $output is 'ARRAY_N' ? array|null : ( + * $output is 'ARRAY_A' ? non-empty-array|null : ( + * $output is 'ARRAY_N' ? non-empty-array|null : ( * WP_Post|null * ) * ) @@ -4452,7 +4456,7 @@ function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array( * * @phpstan-param 'OBJECT'|'ARRAY_A' $output * @phpstan-return ( - * $output is 'ARRAY_A' ? array> : WP_Post[]|false + * $output is 'ARRAY_A' ? array> : WP_Post[]|false * ) */ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { @@ -4485,12 +4489,13 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { // Backward compatibility. Prior to 3.1 expected posts to be returned in array. if ( ARRAY_A === $output ) { + $posts = array(); foreach ( $results as $key => $result ) { - /** @var array $object_vars */ - $object_vars = get_object_vars( $result ); - $results[ $key ] = $object_vars; + /** @var non-empty-array $object_vars */ + $object_vars = get_object_vars( $result ); + $posts[ $key ] = $object_vars; } - return $results ? $results : array(); + return $posts; } return $results ? $results : false; @@ -6146,6 +6151,10 @@ function trackback_url_list( $tb_list, $post_id ) { // Get post data. $postdata = get_post( $post_id, ARRAY_A ); + if ( ! $postdata ) { + return; + } + // Form an excerpt. $excerpt = strip_tags( $postdata['post_excerpt'] ? $postdata['post_excerpt'] : $postdata['post_content'] ); @@ -6206,8 +6215,8 @@ function get_all_page_ids() { * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output * @phpstan-param 'raw'|'edit'|'db'|'display' $filter * @phpstan-return ( - * $output is 'ARRAY_A' ? array|null : ( - * $output is 'ARRAY_N' ? array|null : ( + * $output is 'ARRAY_A' ? non-empty-array|null : ( + * $output is 'ARRAY_N' ? non-empty-array|null : ( * WP_Post|null * ) * ) @@ -6234,8 +6243,8 @@ function get_page( $page, $output = OBJECT, $filter = 'raw' ) { * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output * @phpstan-param string|string[] $post_type * @phpstan-return ( - * $output is 'ARRAY_A' ? array|null : ( - * $output is 'ARRAY_N' ? array|null : ( + * $output is 'ARRAY_A' ? non-empty-array|null : ( + * $output is 'ARRAY_N' ? non-empty-array|null : ( * WP_Post|null * ) * ) diff --git a/src/wp-includes/revision.php b/src/wp-includes/revision.php index 11f2bba9d97ff..6e27fad4fa0a4 100644 --- a/src/wp-includes/revision.php +++ b/src/wp-includes/revision.php @@ -423,6 +423,17 @@ function wp_save_revisioned_meta_fields( $revision_id, $post_id ) { * respectively. Default OBJECT. * @param string $filter Optional sanitization filter. See sanitize_post(). Default 'raw'. * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. + * + * @phpstan-param int|WP_Post $post + * @phpstan-param 'OBJECT'|'ARRAY_A'|'ARRAY_N' $output + * @phpstan-param 'raw'|'edit'|'db'|'display' $filter + * @phpstan-return ( + * $output is 'ARRAY_A' ? non-empty-array|null : ( + * $output is 'ARRAY_N' ? non-empty-array|null : ( + * WP_Post|null + * ) + * ) + * ) */ function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) { $revision = get_post( $post, OBJECT, $filter ); @@ -438,10 +449,13 @@ function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) { if ( OBJECT === $output ) { return $revision; } elseif ( ARRAY_A === $output ) { + /** @var non-empty-array $_revision */ $_revision = get_object_vars( $revision ); return $_revision; } elseif ( ARRAY_N === $output ) { - $_revision = array_values( get_object_vars( $revision ) ); + /** @var non-empty-array $vars */ + $vars = get_object_vars( $revision ); + $_revision = array_values( $vars ); return $_revision; }