Skip to content

Commit be63876

Browse files
Update to WPCS v3 (#419)
* Update to wp-cli-tests v4 (which requires WPCS v3) * Fix all autofixable CS issues * Address PHPCS warning * Ignore a few deprecation notices * Ignore a couple unused parameters * Restore loose comparison to fix test failure --------- Co-authored-by: Daniel Bachhuber <[email protected]>
1 parent 4f39024 commit be63876

22 files changed

+66
-100
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"wp-cli/extension-command": "^1.2 || ^2",
2121
"wp-cli/media-command": "^1.1 || ^2",
2222
"wp-cli/super-admin-command": "^1 || ^2",
23-
"wp-cli/wp-cli-tests": "^3.1"
23+
"wp-cli/wp-cli-tests": "^4"
2424
},
2525
"config": {
2626
"process-timeout": 7200,

entity-command.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
return;
77
}
88

9-
$wpcli_entity_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
9+
$wpcli_entity_autoloader = __DIR__ . '/vendor/autoload.php';
1010
if ( file_exists( $wpcli_entity_autoloader ) ) {
1111
require_once $wpcli_entity_autoloader;
1212
}
@@ -37,7 +37,7 @@
3737
'site meta',
3838
'Site_Meta_Command',
3939
array(
40-
'before_invoke' => function() {
40+
'before_invoke' => function () {
4141
if ( ! is_multisite() ) {
4242
WP_CLI::error( 'This is not a multisite installation.' );
4343
}
@@ -51,7 +51,7 @@
5151
'site option',
5252
'Site_Option_Command',
5353
array(
54-
'before_invoke' => function() {
54+
'before_invoke' => function () {
5555
if ( ! is_multisite() ) {
5656
WP_CLI::error( 'This is not a multisite installation.' );
5757
}
@@ -64,7 +64,7 @@
6464
'term meta',
6565
'Term_Meta_Command',
6666
array(
67-
'before_invoke' => function() {
67+
'before_invoke' => function () {
6868
if ( Utils\wp_version_compare( '4.4', '<' ) ) {
6969
WP_CLI::error( 'Requires WordPress 4.4 or greater.' );
7070
}
@@ -76,7 +76,7 @@
7676
'user application-password',
7777
'User_Application_Password_Command',
7878
array(
79-
'before_invoke' => function() {
79+
'before_invoke' => function () {
8080
if ( Utils\wp_version_compare( '5.6', '<' ) ) {
8181
WP_CLI::error( 'Requires WordPress 5.6 or greater.' );
8282
}
@@ -88,7 +88,7 @@
8888
'user session',
8989
'User_Session_Command',
9090
array(
91-
'before_invoke' => function() {
91+
'before_invoke' => function () {
9292
if ( Utils\wp_version_compare( '4.0', '<' ) ) {
9393
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
9494
}

src/Comment_Command.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ public function generate( $args, $assoc_args ) {
202202
if ( 'progress' === $format ) {
203203
$notify->finish();
204204
}
205-
206205
}
207206

208207
/**
@@ -376,7 +375,7 @@ public function list_( $args, $assoc_args ) {
376375
$comments = wp_list_pluck( $comments, 'comment_ID' );
377376
} elseif ( is_array( $comments ) ) {
378377
$comments = array_map(
379-
function( $comment ) {
378+
function ( $comment ) {
380379
$comment->url = get_comment_link( $comment->comment_ID );
381380
return $comment;
382381
},

src/Menu_Command.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ public function create( $args, $assoc_args ) {
6868

6969
WP_CLI::error( $menu_id->get_error_message() );
7070

71-
} else {
71+
} elseif ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
7272

73-
if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
7473
WP_CLI::line( $menu_id );
75-
} else {
76-
WP_CLI::success( "Created menu {$menu_id}." );
77-
}
74+
} else {
75+
WP_CLI::success( "Created menu {$menu_id}." );
7876
}
7977
}
8078

@@ -99,10 +97,10 @@ public function delete( $args, $assoc_args ) {
9997
$ret = wp_delete_nav_menu( $arg );
10098
if ( ! $ret || is_wp_error( $ret ) ) {
10199
WP_CLI::warning( "Couldn't delete menu '{$arg}'." );
102-
$errors++;
100+
++$errors;
103101
} else {
104102
WP_CLI::log( "Deleted menu '{$arg}'." );
105-
$count++;
103+
++$count;
106104
}
107105
}
108106

@@ -185,7 +183,7 @@ public function list_( $args, $assoc_args ) {
185183

186184
if ( 'ids' === $formatter->format ) {
187185
$ids = array_map(
188-
function( $o ) {
186+
function ( $o ) {
189187
return $o->term_id;
190188
},
191189
$menus
@@ -199,5 +197,4 @@ function( $o ) {
199197
protected function get_formatter( &$assoc_args ) {
200198
return new Formatter( $assoc_args, $this->obj_fields, $this->obj_type );
201199
}
202-
203200
}

src/Menu_Item_Command.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function list_( $args, $assoc_args ) {
9999
// Correct position inconsistency and
100100
// protected `url` param in WP-CLI
101101
$items = array_map(
102-
function( $item ) {
102+
function ( $item ) {
103103
$item->position = $item->menu_order;
104104
$item->link = $item->url;
105105
return $item;
@@ -109,7 +109,7 @@ function( $item ) {
109109

110110
if ( ! empty( $assoc_args['format'] ) && 'ids' === $assoc_args['format'] ) {
111111
$items = array_map(
112-
function( $item ) {
112+
function ( $item ) {
113113
return $item->db_id;
114114
},
115115
$items
@@ -118,7 +118,6 @@ function( $item ) {
118118

119119
$formatter = $this->get_formatter( $assoc_args );
120120
$formatter->display_items( $items );
121-
122121
}
123122

124123
/**
@@ -343,7 +342,6 @@ public function update( $args, $assoc_args ) {
343342
}
344343
$type = get_post_meta( $args[1], '_menu_item_type', true );
345344
$this->add_or_update_item( 'update', $type, $args, $assoc_args );
346-
347345
}
348346

349347
/**
@@ -375,7 +373,7 @@ public function delete( $args, $assoc_args ) {
375373
$result = wp_delete_post( $arg, true );
376374
if ( ! $result ) {
377375
WP_CLI::warning( "Couldn't delete menu item {$arg}." );
378-
$errors++;
376+
++$errors;
379377
} else {
380378

381379
if ( is_array( $menu_term ) && ! empty( $menu_term ) && $post ) {
@@ -395,9 +393,9 @@ public function delete( $args, $assoc_args ) {
395393
}
396394
}
397395

398-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Will increase count for non existent menu.
396+
// phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual -- Will increase count for non existent menu.
399397
if ( false != $result ) {
400-
$count++;
398+
++$count;
401399
}
402400
}
403401

@@ -505,15 +503,12 @@ private function add_or_update_item( $method, $type, $args, $assoc_args ) {
505503

506504
if ( 'add' === $method && ! empty( $assoc_args['porcelain'] ) ) {
507505
WP_CLI::line( $result );
508-
} else {
509-
if ( 'add' === $method ) {
506+
} elseif ( 'add' === $method ) {
510507
WP_CLI::success( 'Menu item added.' );
511-
} elseif ( 'update' === $method ) {
512-
WP_CLI::success( 'Menu item updated.' );
513-
}
508+
} elseif ( 'update' === $method ) {
509+
WP_CLI::success( 'Menu item updated.' );
514510
}
515511
}
516-
517512
}
518513

519514
/**
@@ -534,5 +529,4 @@ private function reorder_menu_items( $menu_id, $min_position, $increment, $ignor
534529
protected function get_formatter( &$assoc_args ) {
535530
return new Formatter( $assoc_args, $this->obj_fields );
536531
}
537-
538532
}

src/Menu_Location_Command.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function list_( $args, $assoc_args ) {
7979

8080
if ( 'ids' === $formatter->format ) {
8181
$ids = array_map(
82-
function( $o ) {
82+
function ( $o ) {
8383
return $o->location;
8484
},
8585
$location_objs
@@ -166,7 +166,5 @@ public function remove( $args, $assoc_args ) {
166166
set_theme_mod( 'nav_menu_locations', $locations );
167167

168168
WP_CLI::success( 'Removed location from menu.' );
169-
170169
}
171-
172170
}

src/Option_Command.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,10 @@ public function update( $args, $assoc_args ) {
427427

428428
if ( $value === $old_value && null === $autoload ) {
429429
WP_CLI::success( "Value passed for '{$key}' option is unchanged." );
430-
} else {
431-
if ( update_option( $key, $value, $autoload ) ) {
430+
} elseif ( update_option( $key, $value, $autoload ) ) {
432431
WP_CLI::success( "Updated '{$key}' option." );
433-
} else {
434-
WP_CLI::error( "Could not update option '{$key}'." );
435-
}
432+
} else {
433+
WP_CLI::error( "Could not update option '{$key}'." );
436434
}
437435
}
438436

@@ -591,7 +589,7 @@ public function pluck( $args, $assoc_args ) {
591589
}
592590

593591
$key_path = array_map(
594-
function( $key ) {
592+
function ( $key ) {
595593
if ( is_numeric( $key ) && ( (string) intval( $key ) === $key ) ) {
596594
return (int) $key;
597595
}
@@ -672,7 +670,7 @@ function( $key ) {
672670
public function patch( $args, $assoc_args ) {
673671
list( $action, $key ) = $args;
674672
$key_path = array_map(
675-
function( $key ) {
673+
function ( $key ) {
676674
if ( is_numeric( $key ) && ( (string) intval( $key ) === $key ) ) {
677675
return (int) $key;
678676
}
@@ -690,12 +688,10 @@ function( $key ) {
690688

691689
if ( ! empty( $stdin_value ) ) {
692690
$patch_value = WP_CLI::read_value( $stdin_value, $assoc_args );
693-
} else {
694-
if ( count( $key_path ) > 1 ) {
691+
} elseif ( count( $key_path ) > 1 ) {
695692
$patch_value = WP_CLI::read_value( array_pop( $key_path ), $assoc_args );
696-
} else {
697-
$patch_value = null;
698-
}
693+
} else {
694+
$patch_value = null;
699695
}
700696

701697
if ( null === $patch_value ) {
@@ -722,12 +718,10 @@ function( $key ) {
722718

723719
if ( $patched_value === $old_value ) {
724720
WP_CLI::success( "Value passed for '{$key}' option is unchanged." );
725-
} else {
726-
if ( update_option( $key, $patched_value ) ) {
721+
} elseif ( update_option( $key, $patched_value ) ) {
727722
WP_CLI::success( "Updated '{$key}' option." );
728-
} else {
729-
WP_CLI::error( "Could not update option '{$key}'." );
730-
}
723+
} else {
724+
WP_CLI::error( "Could not update option '{$key}'." );
731725
}
732726
}
733727

src/Post_Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public function list_( $args, $assoc_args ) {
654654
} else {
655655
$query = new WP_Query( $query_args );
656656
$posts = array_map(
657-
function( $post ) {
657+
function ( $post ) {
658658
$post->url = get_permalink( $post->ID );
659659
return $post;
660660
},
@@ -817,7 +817,7 @@ public function generate( $args, $assoc_args ) {
817817
if ( $this->maybe_make_child() && $current_depth < $post_data['max_depth'] ) {
818818

819819
$current_parent = $previous_post_id;
820-
$current_depth++;
820+
++$current_depth;
821821

822822
} elseif ( $this->maybe_reset_depth() ) {
823823

src/Post_Type_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function list_( $args, $assoc_args ) {
146146
}
147147

148148
$types = array_map(
149-
function( $type ) use ( $counts ) {
149+
function ( $type ) use ( $counts ) {
150150
$type->count = isset( $counts[ $type->name ] ) ? $counts[ $type->name ] : 0;
151151
return $type;
152152
},

src/Site_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ private function insert_default_terms() {
157157
/* translators: Default category slug */
158158
$cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
159159

160+
// phpcs:ignore WordPress.WP.DeprecatedFunctions.global_terms_enabledFound -- Required for backwards compatibility.
160161
if ( global_terms_enabled() ) {
161162
$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
162163
if ( null === $cat_id ) {
@@ -615,7 +616,7 @@ public function list_( $args, $assoc_args ) {
615616

616617
$iterator = Utils\iterator_map(
617618
$iterator,
618-
function( $blog ) {
619+
function ( $blog ) {
619620
$blog->url = trailingslashit( get_home_url( $blog->blog_id ) );
620621
return $blog;
621622
}

0 commit comments

Comments
 (0)