From 59128c92a95e34a4507cbb63c7001e644b842111 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 10 Nov 2025 15:51:25 +0100 Subject: [PATCH 1/2] PHPStan fixes --- src/Comment_Command.php | 4 ++-- src/Term_Command.php | 25 ++++++++++++++++++++----- src/User_Command.php | 2 +- src/WP_CLI/CommandWithMeta.php | 6 ++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 766e28a5..1523e876 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -64,7 +64,7 @@ public function __construct() { * $ wp comment create --comment_post_ID=15 --comment_content="hello blog" --comment_author="wp-cli" * Success: Created comment 932. */ - public function create( $args, $assoc_args ) { + public function create( $args, array $assoc_args ) { $assoc_args = wp_slash( $assoc_args ); parent::_create( $args, @@ -111,7 +111,7 @@ function ( $params ) { * $ wp comment update 123 --comment_author='That Guy' * Success: Updated comment 123. */ - public function update( $args, $assoc_args ) { + public function update( $args, array $assoc_args ) { $assoc_args = wp_slash( $assoc_args ); parent::_update( $args, diff --git a/src/Term_Command.php b/src/Term_Command.php index 489ddf3e..79977bc0 100644 --- a/src/Term_Command.php +++ b/src/Term_Command.php @@ -142,8 +142,14 @@ public function list_( $args, $assoc_args ) { /** * @var \WP_Term[] $terms */ - // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found -- Required for backward compatibility. - $terms = get_terms( $args, $assoc_args ); + $terms = get_terms( + array_merge( + $assoc_args, + [ + 'taxonomy' => $args, + ] + ) + ); } $terms = array_map( @@ -211,7 +217,11 @@ public function create( $args, $assoc_args ) { $assoc_args = wp_slash( $assoc_args ); $term = wp_slash( $term ); - $result = wp_insert_term( $term, $taxonomy, $assoc_args ); + + /** + * @var string $term + */ + $result = wp_insert_term( $term, $taxonomy, $assoc_args ); if ( is_wp_error( $result ) ) { WP_CLI::error( $result->get_error_message() ); @@ -643,8 +653,13 @@ public function recount( $args ) { * @var \WP_Term[] $terms */ - // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found -- Required for backward compatibility. - $terms = get_terms( $taxonomy, [ 'hide_empty' => false ] ); + $terms = get_terms( + [ + 'taxonomy' => $taxonomy, + 'hide_empty' => false, + ] + ); + $term_taxonomy_ids = wp_list_pluck( $terms, 'term_taxonomy_id' ); wp_update_term_count( $term_taxonomy_ids, $taxonomy ); diff --git a/src/User_Command.php b/src/User_Command.php index 6a725687..de5b4f7d 100644 --- a/src/User_Command.php +++ b/src/User_Command.php @@ -554,7 +554,7 @@ public function create( $args, $assoc_args ) { * $ wp user update 123 --display_name=Mary --user_pass=marypass * Success: Updated user 123. */ - public function update( $args, $assoc_args ) { + public function update( $args, array $assoc_args ) { if ( isset( $assoc_args['user_login'] ) ) { WP_CLI::warning( "User logins can't be changed." ); unset( $assoc_args['user_login'] ); diff --git a/src/WP_CLI/CommandWithMeta.php b/src/WP_CLI/CommandWithMeta.php index 2a5ac4b9..d3239199 100644 --- a/src/WP_CLI/CommandWithMeta.php +++ b/src/WP_CLI/CommandWithMeta.php @@ -314,6 +314,9 @@ public function update( $args, $assoc_args ) { $object_id = $this->check_object_id( $object_id ); + /** + * @var array|string $meta_value + */ $meta_value = sanitize_meta( $meta_key, $meta_value, $this->meta_type ); $old_value = sanitize_meta( $meta_key, $this->get_metadata( $object_id, $meta_key, true ), $this->meta_type ); @@ -454,6 +457,9 @@ function ( $key ) { WP_CLI::error( $exception->getMessage() ); } + /** + * @var array|string $patched_meta_value + */ $patched_meta_value = sanitize_meta( $meta_key, $traverser->value(), $this->meta_type ); if ( $patched_meta_value === $old_meta_value ) { From a8548f3522d77f9cde2cf9a22c719c1bc5517d04 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 25 Nov 2025 18:48:26 +0100 Subject: [PATCH 2/2] Use PHPDoc instead --- src/Comment_Command.php | 10 ++++++++-- src/User_Command.php | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 1523e876..ace5a9a6 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -63,8 +63,11 @@ public function __construct() { * # Create comment. * $ wp comment create --comment_post_ID=15 --comment_content="hello blog" --comment_author="wp-cli" * Success: Created comment 932. + * + * @param string[] $args Positional arguments. Unused. + * @param array $assoc_args Associative arguments. */ - public function create( $args, array $assoc_args ) { + public function create( $args, $assoc_args ) { $assoc_args = wp_slash( $assoc_args ); parent::_create( $args, @@ -110,8 +113,11 @@ function ( $params ) { * # Update comment. * $ wp comment update 123 --comment_author='That Guy' * Success: Updated comment 123. + * + * @param string[] $args Positional arguments. Comment IDs to update. + * @param array $assoc_args Associative arguments. */ - public function update( $args, array $assoc_args ) { + public function update( $args, $assoc_args ) { $assoc_args = wp_slash( $assoc_args ); parent::_update( $args, diff --git a/src/User_Command.php b/src/User_Command.php index de5b4f7d..2f45a33b 100644 --- a/src/User_Command.php +++ b/src/User_Command.php @@ -553,8 +553,11 @@ public function create( $args, $assoc_args ) { * # Update user * $ wp user update 123 --display_name=Mary --user_pass=marypass * Success: Updated user 123. + * + * @param string[] $args Positional arguments. Users to update. + * @param array $assoc_args Associative arguments. */ - public function update( $args, array $assoc_args ) { + public function update( $args, $assoc_args ) { if ( isset( $assoc_args['user_login'] ) ) { WP_CLI::warning( "User logins can't be changed." ); unset( $assoc_args['user_login'] );