wordpress-stubs
wordpress-stubs copied to clipboard
PHPStan documentation of wp_update_post() seems to be too restrictive
Since wordpress-stubs 6.0.2 PHPstan triggers errors when we pass $args parameter as an object to wp_update_post() function as it's allowed.
https://github.com/WordPress/WordPress/blob/6.0.2/wp-includes/post.php#L4703-L4718
The issue is closer than @chouby one, however it seems to us that the PHPStan documentation isn't correct in the wp_update_post() function case.
for example
$post = get_post( $post_id );
$post->post_status = 'draft';
wp_update_post( $post );
triggers
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
178 Parameter #1 $postarr of function wp_update_post expects array{ID?: int, post_author?: int, post_date?: string, post_date_gmt?: string, post_content?: string, post_content_filtered?: string, post_title?: string, post_excerpt?: string, ...}, WP_Post given.
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Good spot. This was caused by #49.
The parameter is documented in WordPress as @param array|object $postarr but the PHPStan tag that gets added is @phpstan-param array{ ... } $postarr.
Related: https://github.com/phpstan/phpstan/issues/2923
PHPStan documentation isn't correct in the
wp_update_post()function case.
Yes, please see my latest comment.
Since https://github.com/phpstan/phpstan/issues/2923 PHPStan 1.10.12+ supports object shapes now, so we could implement this as a shape on object. Unfortunately it would require the whole set of properties to be duplicated, as you can't use array|object{ ... } or (array|object){ ... }. Still, the generate script would handle that.
@phpstan-param array{ ... }|object{ ... } $postarr
https://github.com/phpstan/phpdoc-parser/issues/187