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

Update to WPCS v3 #419

Merged
merged 6 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions entity-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.' );
}
Expand All @@ -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.' );
}
Expand All @@ -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.' );
}
Expand All @@ -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.' );
}
Expand All @@ -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.' );
}
Expand Down
3 changes: 1 addition & 2 deletions src/Comment_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public function generate( $args, $assoc_args ) {
if ( 'progress' === $format ) {
$notify->finish();
}

}

/**
Expand Down Expand Up @@ -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;
},
Expand Down
15 changes: 6 additions & 9 deletions src/Menu_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}." );
}
}

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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
Expand All @@ -199,5 +197,4 @@ function( $o ) {
protected function get_formatter( &$assoc_args ) {
return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type );
}

}
22 changes: 8 additions & 14 deletions src/Menu_Item_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -118,7 +118,6 @@ function( $item ) {

$formatter = $this->get_formatter( $assoc_args );
$formatter->display_items( $items );

}

/**
Expand Down Expand Up @@ -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 );

}

/**
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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.' );
}
}

}

/**
Expand All @@ -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 );
}

}
4 changes: 1 addition & 3 deletions src/Menu_Location_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,7 +166,5 @@ public function remove( $args, $assoc_args ) {
set_theme_mod( 'nav_menu_locations', $locations );

WP_CLI::success( 'Removed location from menu.' );

}

}
28 changes: 11 additions & 17 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}'." );
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 ) {
Expand All @@ -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}'." );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Post_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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() ) {

Expand Down
2 changes: 1 addition & 1 deletion src/Post_Type_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
3 changes: 2 additions & 1 deletion src/Site_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/Site_Meta_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

}
20 changes: 8 additions & 12 deletions src/Site_Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}'." );
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}'." );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Taxonomy_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading