diff --git a/composer.json b/composer.json index c4fc10555..83f264c3a 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "wp-cli/extension-command": "^1.2 || ^2", "wp-cli/media-command": "^1.1 || ^2", "wp-cli/super-admin-command": "^1 || ^2", - "wp-cli/wp-cli-tests": "^3.1" + "wp-cli/wp-cli-tests": "^4" }, "config": { "process-timeout": 7200, diff --git a/entity-command.php b/entity-command.php index 19a94498d..a9e5381d9 100644 --- a/entity-command.php +++ b/entity-command.php @@ -6,7 +6,7 @@ return; } -$wpcli_entity_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; +$wpcli_entity_autoloader = __DIR__ . '/vendor/autoload.php'; if ( file_exists( $wpcli_entity_autoloader ) ) { require_once $wpcli_entity_autoloader; } @@ -37,7 +37,7 @@ 'site meta', 'Site_Meta_Command', array( - 'before_invoke' => function() { + 'before_invoke' => function () { if ( ! is_multisite() ) { WP_CLI::error( 'This is not a multisite installation.' ); } @@ -51,7 +51,7 @@ 'site option', 'Site_Option_Command', array( - 'before_invoke' => function() { + 'before_invoke' => function () { if ( ! is_multisite() ) { WP_CLI::error( 'This is not a multisite installation.' ); } @@ -64,7 +64,7 @@ 'term meta', 'Term_Meta_Command', array( - 'before_invoke' => function() { + 'before_invoke' => function () { if ( Utils\wp_version_compare( '4.4', '<' ) ) { WP_CLI::error( 'Requires WordPress 4.4 or greater.' ); } @@ -76,7 +76,7 @@ 'user application-password', 'User_Application_Password_Command', array( - 'before_invoke' => function() { + 'before_invoke' => function () { if ( Utils\wp_version_compare( '5.6', '<' ) ) { WP_CLI::error( 'Requires WordPress 5.6 or greater.' ); } @@ -88,7 +88,7 @@ 'user session', 'User_Session_Command', array( - 'before_invoke' => function() { + 'before_invoke' => function () { if ( Utils\wp_version_compare( '4.0', '<' ) ) { WP_CLI::error( 'Requires WordPress 4.0 or greater.' ); } diff --git a/src/Comment_Command.php b/src/Comment_Command.php index ebbc56c58..99f43fdf5 100644 --- a/src/Comment_Command.php +++ b/src/Comment_Command.php @@ -202,7 +202,6 @@ public function generate( $args, $assoc_args ) { if ( 'progress' === $format ) { $notify->finish(); } - } /** @@ -376,7 +375,7 @@ public function list_( $args, $assoc_args ) { $comments = wp_list_pluck( $comments, 'comment_ID' ); } elseif ( is_array( $comments ) ) { $comments = array_map( - function( $comment ) { + function ( $comment ) { $comment->url = get_comment_link( $comment->comment_ID ); return $comment; }, diff --git a/src/Menu_Command.php b/src/Menu_Command.php index 7900fa14e..bb9f6901d 100644 --- a/src/Menu_Command.php +++ b/src/Menu_Command.php @@ -68,13 +68,11 @@ public function create( $args, $assoc_args ) { WP_CLI::error( $menu_id->get_error_message() ); - } else { + } elseif ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) { - if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) { WP_CLI::line( $menu_id ); - } else { - WP_CLI::success( "Created menu {$menu_id}." ); - } + } else { + WP_CLI::success( "Created menu {$menu_id}." ); } } @@ -99,10 +97,10 @@ public function delete( $args, $assoc_args ) { $ret = wp_delete_nav_menu( $arg ); if ( ! $ret || is_wp_error( $ret ) ) { WP_CLI::warning( "Couldn't delete menu '{$arg}'." ); - $errors++; + ++$errors; } else { WP_CLI::log( "Deleted menu '{$arg}'." ); - $count++; + ++$count; } } @@ -185,7 +183,7 @@ public function list_( $args, $assoc_args ) { if ( 'ids' === $formatter->format ) { $ids = array_map( - function( $o ) { + function ( $o ) { return $o->term_id; }, $menus @@ -199,5 +197,4 @@ function( $o ) { protected function get_formatter( &$assoc_args ) { return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type ); } - } diff --git a/src/Menu_Item_Command.php b/src/Menu_Item_Command.php index 75ee1ce33..19f96cf99 100644 --- a/src/Menu_Item_Command.php +++ b/src/Menu_Item_Command.php @@ -99,7 +99,7 @@ public function list_( $args, $assoc_args ) { // Correct position inconsistency and // protected `url` param in WP-CLI $items = array_map( - function( $item ) { + function ( $item ) { $item->position = $item->menu_order; $item->link = $item->url; return $item; @@ -109,7 +109,7 @@ function( $item ) { if ( ! empty( $assoc_args['format'] ) && 'ids' === $assoc_args['format'] ) { $items = array_map( - function( $item ) { + function ( $item ) { return $item->db_id; }, $items @@ -118,7 +118,6 @@ function( $item ) { $formatter = $this->get_formatter( $assoc_args ); $formatter->display_items( $items ); - } /** @@ -343,7 +342,6 @@ public function update( $args, $assoc_args ) { } $type = get_post_meta( $args[1], '_menu_item_type', true ); $this->add_or_update_item( 'update', $type, $args, $assoc_args ); - } /** @@ -375,7 +373,7 @@ public function delete( $args, $assoc_args ) { $result = wp_delete_post( $arg, true ); if ( ! $result ) { WP_CLI::warning( "Couldn't delete menu item {$arg}." ); - $errors++; + ++$errors; } else { if ( is_array( $menu_term ) && ! empty( $menu_term ) && $post ) { @@ -395,9 +393,9 @@ public function delete( $args, $assoc_args ) { } } - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Will increase count for non existent menu. + // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual -- Will increase count for non existent menu. if ( false != $result ) { - $count++; + ++$count; } } @@ -505,15 +503,12 @@ private function add_or_update_item( $method, $type, $args, $assoc_args ) { if ( 'add' === $method && ! empty( $assoc_args['porcelain'] ) ) { WP_CLI::line( $result ); - } else { - if ( 'add' === $method ) { + } elseif ( 'add' === $method ) { WP_CLI::success( 'Menu item added.' ); - } elseif ( 'update' === $method ) { - WP_CLI::success( 'Menu item updated.' ); - } + } elseif ( 'update' === $method ) { + WP_CLI::success( 'Menu item updated.' ); } } - } /** @@ -534,5 +529,4 @@ private function reorder_menu_items( $menu_id, $min_position, $increment, $ignor protected function get_formatter( &$assoc_args ) { return new Formatter( $assoc_args, $this->obj_fields ); } - } diff --git a/src/Menu_Location_Command.php b/src/Menu_Location_Command.php index 0a11e4e43..508ff486f 100644 --- a/src/Menu_Location_Command.php +++ b/src/Menu_Location_Command.php @@ -79,7 +79,7 @@ public function list_( $args, $assoc_args ) { if ( 'ids' === $formatter->format ) { $ids = array_map( - function( $o ) { + function ( $o ) { return $o->location; }, $location_objs @@ -166,7 +166,5 @@ public function remove( $args, $assoc_args ) { set_theme_mod( 'nav_menu_locations', $locations ); WP_CLI::success( 'Removed location from menu.' ); - } - } diff --git a/src/Option_Command.php b/src/Option_Command.php index 241906f15..53d44db35 100644 --- a/src/Option_Command.php +++ b/src/Option_Command.php @@ -427,12 +427,10 @@ public function update( $args, $assoc_args ) { if ( $value === $old_value && null === $autoload ) { WP_CLI::success( "Value passed for '{$key}' option is unchanged." ); - } else { - if ( update_option( $key, $value, $autoload ) ) { + } elseif ( update_option( $key, $value, $autoload ) ) { WP_CLI::success( "Updated '{$key}' option." ); - } else { - WP_CLI::error( "Could not update option '{$key}'." ); - } + } else { + WP_CLI::error( "Could not update option '{$key}'." ); } } @@ -591,7 +589,7 @@ public function pluck( $args, $assoc_args ) { } $key_path = array_map( - function( $key ) { + function ( $key ) { if ( is_numeric( $key ) && ( (string) intval( $key ) === $key ) ) { return (int) $key; } @@ -672,7 +670,7 @@ function( $key ) { public function patch( $args, $assoc_args ) { list( $action, $key ) = $args; $key_path = array_map( - function( $key ) { + function ( $key ) { if ( is_numeric( $key ) && ( (string) intval( $key ) === $key ) ) { return (int) $key; } @@ -690,12 +688,10 @@ function( $key ) { if ( ! empty( $stdin_value ) ) { $patch_value = WP_CLI::read_value( $stdin_value, $assoc_args ); - } else { - if ( count( $key_path ) > 1 ) { + } elseif ( count( $key_path ) > 1 ) { $patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args ); - } else { - $patch_value = null; - } + } else { + $patch_value = null; } if ( null === $patch_value ) { @@ -722,12 +718,10 @@ function( $key ) { if ( $patched_value === $old_value ) { WP_CLI::success( "Value passed for '{$key}' option is unchanged." ); - } else { - if ( update_option( $key, $patched_value ) ) { + } elseif ( update_option( $key, $patched_value ) ) { WP_CLI::success( "Updated '{$key}' option." ); - } else { - WP_CLI::error( "Could not update option '{$key}'." ); - } + } else { + WP_CLI::error( "Could not update option '{$key}'." ); } } diff --git a/src/Post_Command.php b/src/Post_Command.php index 797dcd350..48257a94d 100644 --- a/src/Post_Command.php +++ b/src/Post_Command.php @@ -654,7 +654,7 @@ public function list_( $args, $assoc_args ) { } else { $query = new WP_Query( $query_args ); $posts = array_map( - function( $post ) { + function ( $post ) { $post->url = get_permalink( $post->ID ); return $post; }, @@ -817,7 +817,7 @@ public function generate( $args, $assoc_args ) { if ( $this->maybe_make_child() && $current_depth < $post_data['max_depth'] ) { $current_parent = $previous_post_id; - $current_depth++; + ++$current_depth; } elseif ( $this->maybe_reset_depth() ) { diff --git a/src/Post_Type_Command.php b/src/Post_Type_Command.php index 37973e28d..88c01029a 100644 --- a/src/Post_Type_Command.php +++ b/src/Post_Type_Command.php @@ -146,7 +146,7 @@ public function list_( $args, $assoc_args ) { } $types = array_map( - function( $type ) use ( $counts ) { + function ( $type ) use ( $counts ) { $type->count = isset( $counts[ $type->name ] ) ? $counts[ $type->name ] : 0; return $type; }, diff --git a/src/Site_Command.php b/src/Site_Command.php index 7ed699d40..a074a9723 100644 --- a/src/Site_Command.php +++ b/src/Site_Command.php @@ -157,6 +157,7 @@ private function insert_default_terms() { /* translators: Default category slug */ $cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) ); + // phpcs:ignore WordPress.WP.DeprecatedFunctions.global_terms_enabledFound -- Required for backwards compatibility. if ( global_terms_enabled() ) { $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); if ( null === $cat_id ) { @@ -615,7 +616,7 @@ public function list_( $args, $assoc_args ) { $iterator = Utils\iterator_map( $iterator, - function( $blog ) { + function ( $blog ) { $blog->url = trailingslashit( get_home_url( $blog->blog_id ) ); return $blog; } diff --git a/src/Site_Meta_Command.php b/src/Site_Meta_Command.php index d07b81060..acc587417 100644 --- a/src/Site_Meta_Command.php +++ b/src/Site_Meta_Command.php @@ -111,5 +111,4 @@ protected function get_metadata( $object_id, $meta_key = '', $single = false ) { protected function delete_metadata( $object_id, $meta_key, $meta_value = '' ) { return delete_site_meta( $object_id, $meta_key, $meta_value ); } - } diff --git a/src/Site_Option_Command.php b/src/Site_Option_Command.php index 0dd3e42e8..d5201a602 100644 --- a/src/Site_Option_Command.php +++ b/src/Site_Option_Command.php @@ -245,12 +245,10 @@ public function update( $args, $assoc_args ) { if ( $value === $old_value ) { WP_CLI::success( "Value passed for '{$key}' site option is unchanged." ); - } else { - if ( update_site_option( $key, $value ) ) { + } elseif ( update_site_option( $key, $value ) ) { WP_CLI::success( "Updated '{$key}' site option." ); - } else { - WP_CLI::error( "Could not update site option '{$key}'." ); - } + } else { + WP_CLI::error( "Could not update site option '{$key}'." ); } } @@ -307,7 +305,7 @@ public function pluck( $args, $assoc_args ) { } $key_path = array_map( - function( $key ) { + function ( $key ) { if ( is_numeric( $key ) && ( (string) intval( $key ) === $key ) ) { return (int) $key; } @@ -362,7 +360,7 @@ function( $key ) { public function patch( $args, $assoc_args ) { list( $action, $key ) = $args; $key_path = array_map( - function( $key ) { + function ( $key ) { if ( is_numeric( $key ) && ( (string) intval( $key ) === $key ) ) { return (int) $key; } @@ -401,12 +399,10 @@ function( $key ) { if ( $patched_value === $old_value ) { WP_CLI::success( "Value passed for '{$key}' site option is unchanged." ); - } else { - if ( update_site_option( $key, $patched_value ) ) { + } elseif ( update_site_option( $key, $patched_value ) ) { WP_CLI::success( "Updated '{$key}' site option." ); - } else { - WP_CLI::error( "Could not update site option '{$key}'." ); - } + } else { + WP_CLI::error( "Could not update site option '{$key}'." ); } } diff --git a/src/Taxonomy_Command.php b/src/Taxonomy_Command.php index 21d33c9ad..1f1d05f97 100644 --- a/src/Taxonomy_Command.php +++ b/src/Taxonomy_Command.php @@ -172,7 +172,7 @@ public function list_( $args, $assoc_args ) { } $taxonomies = array_map( - function( $taxonomy ) use ( $counts ) { + function ( $taxonomy ) use ( $counts ) { $taxonomy->object_type = implode( ', ', $taxonomy->object_type ); $taxonomy->count = isset( $counts[ $taxonomy->name ] ) ? $counts[ $taxonomy->name ] : 0; return $taxonomy; diff --git a/src/Term_Command.php b/src/Term_Command.php index 8769801aa..16db93615 100644 --- a/src/Term_Command.php +++ b/src/Term_Command.php @@ -150,11 +150,12 @@ public function list_( $args, $assoc_args ) { } } } else { + // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found -- Required for backward compatibility. $terms = get_terms( $args, $assoc_args ); } $terms = array_map( - function( $term ) { + function ( $term ) { $term->count = (int) $term->count; $term->parent = (int) $term->parent; $term->url = get_term_link( $term ); @@ -225,12 +226,10 @@ public function create( $args, $assoc_args ) { if ( is_wp_error( $result ) ) { WP_CLI::error( $result->get_error_message() ); - } else { - if ( $porcelain ) { + } elseif ( $porcelain ) { WP_CLI::line( $result['term_id'] ); - } else { - WP_CLI::success( "Created {$taxonomy} {$result['term_id']}." ); - } + } else { + WP_CLI::success( "Created {$taxonomy} {$result['term_id']}." ); } } @@ -457,10 +456,10 @@ public function delete( $args, $assoc_args ) { if ( is_wp_error( $result ) ) { WP_CLI::warning( $result ); - $errors++; + ++$errors; } elseif ( $result ) { WP_CLI::log( "Deleted {$taxonomy} {$term_id}." ); - $successes++; + ++$successes; } else { WP_CLI::warning( "{$taxonomy} {$term_id} doesn't exist." ); } @@ -557,7 +556,7 @@ public function generate( $args, $assoc_args ) { if ( $previous_term_id && $this->maybe_make_child() && $current_depth < $max_depth ) { $current_parent = $previous_term_id; - $current_depth++; + ++$current_depth; } elseif ( $this->maybe_reset_depth() ) { @@ -637,6 +636,7 @@ public function recount( $args ) { WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." ); } else { + // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found -- Required for backward compatibility. $terms = get_terms( $taxonomy, [ 'hide_empty' => false ] ); $term_taxonomy_ids = wp_list_pluck( $terms, 'term_taxonomy_id' ); diff --git a/src/User_Application_Password_Command.php b/src/User_Application_Password_Command.php index 886675405..3927cd156 100644 --- a/src/User_Application_Password_Command.php +++ b/src/User_Application_Password_Command.php @@ -388,7 +388,7 @@ public function update( $args, $assoc_args ) { * @param array $assoc_args Associative array of associative arguments. * @throws ExitException If the application password could not be created. */ - public function record_usage( $args, $assoc_args ) { + public function record_usage( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed $args = $this->replace_login_with_user_id( $args ); list( $user_id, $uuid ) = $args; @@ -454,7 +454,7 @@ public function delete( $args, $assoc_args ) { if ( $result instanceof WP_Error ) { WP_CLI::warning( "Failed to delete UUID {$uuid}: " . $result->get_error_message() ); - $errors++; + ++$errors; } } @@ -497,7 +497,7 @@ public function delete( $args, $assoc_args ) { * @param array $assoc_args Associative array of associative arguments. * @throws ExitException If the application password could not be created. */ - public function exists( $args, $assoc_args ) { + public function exists( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed $args = $this->replace_login_with_user_id( $args ); list( $user_id, $app_name ) = $args; diff --git a/src/User_Command.php b/src/User_Command.php index 78dcbea05..e0fbd867c 100644 --- a/src/User_Command.php +++ b/src/User_Command.php @@ -450,11 +450,9 @@ public function create( $args, $assoc_args ) { $user_id = 'Unknown error creating new user.'; } WP_CLI::error( $user_id ); - } else { - if ( false === $user->role ) { + } elseif ( false === $user->role ) { delete_user_option( $user_id, 'capabilities' ); delete_user_option( $user_id, 'user_level' ); - } } if ( Utils\get_flag_value( $assoc_args, 'send-email' ) ) { @@ -1188,7 +1186,6 @@ private static function validate_role( $role, $warn_user_only = false ) { WP_CLI::error( "Role doesn't exist: {$role}" ); } } - } /** @@ -1314,7 +1311,7 @@ private function update_msuser_status( $user_ids, $pref, $value ) { } WP_CLI::log( "User {$user_id} {$action}." ); - $successes++; + ++$successes; } Utils\report_batch_operation_results( 'user', $verb, count( $user_ids ), $successes, $errors ); @@ -1364,5 +1361,4 @@ public function check_password( $args, $assoc_args ) { WP_CLI::halt( 1 ); } } - } diff --git a/src/User_Meta_Command.php b/src/User_Meta_Command.php index 48d0974db..c5ee80337 100644 --- a/src/User_Meta_Command.php +++ b/src/User_Meta_Command.php @@ -324,5 +324,4 @@ private function replace_login_with_user_id( $args ) { $args[0] = $user->ID; return $args; } - } diff --git a/src/User_Session_Command.php b/src/User_Session_Command.php index db1ed88d4..e4efd59ce 100644 --- a/src/User_Session_Command.php +++ b/src/User_Session_Command.php @@ -176,7 +176,7 @@ protected function get_all_sessions( WP_Session_Tokens $manager ) { array_walk( $sessions, - function( &$session, $token ) { + function ( &$session, $token ) { $session['token'] = $token; $session['login_time'] = date( 'Y-m-d H:i:s', $session['login'] ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date $session['expiration_time'] = date( 'Y-m-d H:i:s', $session['expiration'] ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date @@ -195,5 +195,4 @@ protected function destroy_session( WP_Session_Tokens $manager, $token ) { private function get_formatter( &$assoc_args ) { return new Formatter( $assoc_args, $this->fields ); } - } diff --git a/src/WP_CLI/CommandWithMeta.php b/src/WP_CLI/CommandWithMeta.php index 2a8a2b815..d30ee93f4 100644 --- a/src/WP_CLI/CommandWithMeta.php +++ b/src/WP_CLI/CommandWithMeta.php @@ -129,7 +129,6 @@ function ( $a, $b ) use ( $orderby, $order ) { $formatter = new Formatter( $assoc_args, $fields, $this->meta_type ); $formatter->display_items( $items ); - } /** @@ -311,7 +310,6 @@ public function update( $args, $assoc_args ) { WP_CLI::error( "Failed to update custom field '{$meta_key}'." ); } } - } /** @@ -402,7 +400,7 @@ public function patch( $args, $assoc_args ) { list( $action, $object_id, $meta_key ) = $args; $object_id = $this->check_object_id( $object_id ); $key_path = array_map( - function( $key ) { + function ( $key ) { if ( is_numeric( $key ) && ( (string) intval( $key ) === $key ) ) { return (int) $key; } @@ -549,5 +547,4 @@ protected function check_object_id( $object_id ) { // Needs to be set in subclass return $object_id; } - } diff --git a/src/WP_CLI/CommandWithTerms.php b/src/WP_CLI/CommandWithTerms.php index 548dd7cd3..ddc558a8d 100644 --- a/src/WP_CLI/CommandWithTerms.php +++ b/src/WP_CLI/CommandWithTerms.php @@ -105,7 +105,6 @@ public function list_( $args, $assoc_args ) { $formatter = $this->get_formatter( $assoc_args ); $formatter->display_items( $items ); - } @@ -366,4 +365,3 @@ protected function get_formatter( &$assoc_args ) { return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type ); } } - diff --git a/src/WP_CLI/Entity/RecursiveDataStructureTraverser.php b/src/WP_CLI/Entity/RecursiveDataStructureTraverser.php index ace1a4918..f9573b701 100644 --- a/src/WP_CLI/Entity/RecursiveDataStructureTraverser.php +++ b/src/WP_CLI/Entity/RecursiveDataStructureTraverser.php @@ -28,10 +28,10 @@ class RecursiveDataStructureTraverser { * @param string|int $key The key/property the data belongs to. * @param static $parent */ - public function __construct( &$data, $key = null, $parent = null ) { + public function __construct( &$data, $key = null, $parent_instance = null ) { $this->data =& $data; $this->key = $key; - $this->parent = $parent; + $this->parent = $parent_instance; } /** diff --git a/tests/RecursiveDataStructureTraverserTest.php b/tests/RecursiveDataStructureTraverserTest.php index 31743e491..c7aebce63 100644 --- a/tests/RecursiveDataStructureTraverserTest.php +++ b/tests/RecursiveDataStructureTraverserTest.php @@ -159,5 +159,4 @@ public function it_throws_an_exception_when_attempting_to_create_a_key_on_an_inv $this->fail( 'Failed to assert that an exception was thrown when inserting a key into a string.' ); } - }