Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPStan documentation of wp_update_post() seems to be too restrictive #55

Open
manooweb opened this issue Oct 5, 2022 · 5 comments
Open

Comments

@manooweb
Copy link

manooweb commented Oct 5, 2022

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.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@johnbillion
Copy link
Contributor

johnbillion commented Oct 5, 2022

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.

@johnbillion
Copy link
Contributor

Related: phpstan/phpstan#2923

@szepeviktor
Copy link
Member

PHPStan documentation isn't correct in the wp_update_post() function case.

Yes, please see my latest comment.

@johnbillion
Copy link
Contributor

Since phpstan/phpstan#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

@johnbillion
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants