diff --git a/entity-command.php b/entity-command.php index 0cecf202b..aac8b69ce 100644 --- a/entity-command.php +++ b/entity-command.php @@ -54,11 +54,15 @@ 'Site_Meta_Command', array( 'before_invoke' => function () { + /** + * @var \wpdb $wpdb + */ + global $wpdb; if ( ! is_multisite() ) { WP_CLI::error( 'This is not a multisite installation.' ); } if ( ! function_exists( 'is_site_meta_supported' ) || ! is_site_meta_supported() ) { - WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $GLOBALS['wpdb']->blogmeta ) ); + WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $wpdb->blogmeta ) ); } }, ) diff --git a/features/post-block.feature b/features/post-block.feature index bfcfc9ca9..23a760e75 100644 --- a/features/post-block.feature +++ b/features/post-block.feature @@ -127,9 +127,15 @@ Feature: Manage blocks in post content Then save STDOUT as {POST_ID} When I run `wp post block render {POST_ID}` + # In WordPress 7.0+ paragraph blocks are rendered with a class name. + # See https://github.com/WordPress/gutenberg/pull/71207. Then STDOUT should contain: """ -

Hello World

+

Hello World

""" And STDOUT should contain: """ @@ -143,7 +149,11 @@ Feature: Manage blocks in post content When I run `wp post block render {POST_ID} --block=core/paragraph` Then STDOUT should contain: """ -

Hello World

+

Hello World

""" And STDOUT should not contain: """ @@ -773,9 +783,15 @@ Feature: Manage blocks in post content Then save STDOUT as {POST_ID} When I run `wp post block export {POST_ID} --format=html` + # In WordPress 7.0+ paragraph blocks are rendered with a class name. + # See https://github.com/WordPress/gutenberg/pull/71207. Then STDOUT should contain: """ -

Hello World

+

Hello World

""" @require-wp-5.0 diff --git a/src/Comment_Command.php b/src/Comment_Command.php index 034a96668..5ef1acdb4 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -94,7 +94,7 @@ public function __construct() { * * # Create a note (WordPress 6.9+). * $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note" - * Success: Created comment 933.
 * + * Success: Created comment 933. * * @param string[] $args Positional arguments. Unused. * @param array $assoc_args Associative arguments. */ @@ -279,6 +279,7 @@ public function get( $args, $assoc_args ) { WP_CLI::error( 'Invalid comment ID.' ); } + // @phpstan-ignore property.notFound if ( ! isset( $comment->url ) ) { // @phpstan-ignore property.notFound $comment->url = get_comment_link( $comment ); @@ -447,8 +448,12 @@ public function list_( $args, $assoc_args ) { } elseif ( is_array( $comments ) ) { $comments = array_map( function ( $comment ) { - $comment->url = get_comment_link( $comment->comment_ID ); - return $comment; + /** + * @var \WP_Comment $comment + */ + // @phpstan-ignore property.notFound + $comment->url = get_comment_link( (int) $comment->comment_ID ); + return $comment; }, $comments ); diff --git a/src/Post_Block_Command.php b/src/Post_Block_Command.php index 11482e54d..ebca6e454 100644 --- a/src/Post_Block_Command.php +++ b/src/Post_Block_Command.php @@ -31,6 +31,9 @@ * $ wp post block insert 123 core/paragraph --content="Hello World" * * @package wp-cli + * + * @phpstan-type ParsedBlock array{blockName?: string, attrs: array, innerBlocks: array>, innerHTML: string, innerContent: list} + * @phpstan-type ParsedBlockWithBlockName array{blockName: string, attrs: array, innerBlocks: array>, innerHTML: string, innerContent: list} */ class Post_Block_Command extends WP_CLI_Command { @@ -641,6 +644,10 @@ public function import( $args, $assoc_args ) { WP_CLI::error( 'No blocks found in import data.' ); } + /** + * @phpstan-var array $import_blocks + */ + // Validate block structure. foreach ( $import_blocks as $idx => $block ) { if ( ! isset( $block['blockName'] ) ) { @@ -648,6 +655,10 @@ public function import( $args, $assoc_args ) { } } + /** + * @phpstan-var array $import_blocks + */ + $imported_count = count( $import_blocks ); if ( $replace ) { diff --git a/src/Site_Command.php b/src/Site_Command.php index 6aafffabd..e1ded0171 100644 --- a/src/Site_Command.php +++ b/src/Site_Command.php @@ -1244,7 +1244,6 @@ private function get_sites_ids( $args, $assoc_args ) { * @param array $assoc_args Passed-in parameters. * * @return bool - * @throws ExitException If neither site ids nor site slug using --slug were provided. */ private function check_site_ids_and_slug( $args, $assoc_args ) { if ( ( empty( $args ) && empty( $assoc_args['slug'] ) ) diff --git a/src/Term_Command.php b/src/Term_Command.php index 4927512d7..6547d834c 100644 --- a/src/Term_Command.php +++ b/src/Term_Command.php @@ -140,9 +140,6 @@ public function list_( $args, $assoc_args ) { $term = get_term_by( 'id', $assoc_args['term_id'], $args[0] ); $terms = [ $term ]; } else { - /** - * @var \WP_Term[] $terms - */ $terms = get_terms( array_merge( $assoc_args, @@ -151,6 +148,15 @@ public function list_( $args, $assoc_args ) { ] ) ); + + // This should never happen because of the taxonomy_exists check above. + if ( is_wp_error( $terms ) ) { + WP_CLI::error( $terms ); + } + + /** + * @var \WP_Term[] $terms + */ } $terms = array_map( @@ -295,6 +301,7 @@ public function get( $args, $assoc_args ) { WP_CLI::error( "Term doesn't exist." ); } + // @phpstan-ignore property.notFound if ( ! isset( $term->url ) ) { // @phpstan-ignore property.notFound $term->url = get_term_link( $term ); @@ -649,11 +656,6 @@ public function recount( $args ) { if ( ! taxonomy_exists( $taxonomy ) ) { WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." ); } else { - - /** - * @var \WP_Term[] $terms - */ - $terms = get_terms( [ 'taxonomy' => $taxonomy, @@ -661,6 +663,16 @@ public function recount( $args ) { ] ); + // This should never happen because of the taxonomy_exists check above. + if ( is_wp_error( $terms ) ) { + WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." ); + continue; + } + + /** + * @var \WP_Term[] $terms + */ + $term_taxonomy_ids = wp_list_pluck( $terms, 'term_taxonomy_id' ); wp_update_term_count( $term_taxonomy_ids, $taxonomy ); diff --git a/src/User_Meta_Command.php b/src/User_Meta_Command.php index 344488f65..9b2e35217 100644 --- a/src/User_Meta_Command.php +++ b/src/User_Meta_Command.php @@ -341,6 +341,9 @@ protected function delete_metadata( $object_id, $meta_key, $meta_value = '' ) { private function replace_login_with_user_id( $args ) { $user = $this->fetcher->get_check( $args[0] ); $args[0] = $user->ID; + // TODO: Improve method type eventually. + // Related: https://github.com/phpstan/phpstan/issues/8438. + // @phpstan-ignore return.type return $args; } } diff --git a/src/User_Session_Command.php b/src/User_Session_Command.php index d20f94c47..7e4262484 100644 --- a/src/User_Session_Command.php +++ b/src/User_Session_Command.php @@ -174,6 +174,7 @@ protected function get_all_sessions( WP_Session_Tokens $manager ) { // Make the private session data accessible to WP-CLI $get_sessions = new ReflectionMethod( $manager, 'get_sessions' ); if ( PHP_VERSION_ID < 80100 ) { + // @phpstan-ignore method.deprecated $get_sessions->setAccessible( true ); } @@ -197,6 +198,7 @@ function ( &$session, $token ) { protected function destroy_session( WP_Session_Tokens $manager, $token ) { $update_session = new ReflectionMethod( $manager, 'update_session' ); if ( PHP_VERSION_ID < 80100 ) { + // @phpstan-ignore method.deprecated $update_session->setAccessible( true ); } return $update_session->invoke( $manager, $token, null ); diff --git a/src/WP_CLI/CommandWithTerms.php b/src/WP_CLI/CommandWithTerms.php index 0e4f9c4da..a70347233 100644 --- a/src/WP_CLI/CommandWithTerms.php +++ b/src/WP_CLI/CommandWithTerms.php @@ -103,10 +103,16 @@ public function list_( $args, $assoc_args ) { $taxonomy_args['fields'] = 'ids'; } + $items = wp_get_object_terms( $object_id, $taxonomy_names, $taxonomy_args ); + + // This should never happen because of the taxonomy_exists check above. + if ( is_wp_error( $items ) ) { + WP_CLI::error( $items ); + } + /** * @var \WP_Term[] $items */ - $items = wp_get_object_terms( $object_id, $taxonomy_names, $taxonomy_args ); $formatter = $this->get_formatter( $assoc_args ); $formatter->display_items( $items );