Skip to content

Commit f323174

Browse files
committed
Avoid variable abbreviations
1 parent 1787646 commit f323174

11 files changed

+69
-67
lines changed

src/Comment_Command.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ function ( $comment_id, $assoc_args ) {
413413
$force = Utils\get_flag_value( $assoc_args, 'force' );
414414

415415
$status = wp_get_comment_status( $comment_id );
416-
$r = wp_delete_comment( $comment_id, $force );
416+
$result = wp_delete_comment( $comment_id, $force );
417417

418-
if ( $r ) {
418+
if ( $result ) {
419419
if ( $force || 'trash' === $status ) {
420420
return [ 'success', "Deleted comment $comment_id." ];
421421
} else {
@@ -443,10 +443,10 @@ private function call( $args, $status, $success, $failure ) {
443443
private function set_status( $args, $status, $success ) {
444444
$comment = $this->fetcher->get_check( $args );
445445

446-
$r = wp_set_comment_status( $comment->comment_ID, $status, true );
446+
$result = wp_set_comment_status( $comment->comment_ID, $status, true );
447447

448-
if ( is_wp_error( $r ) ) {
449-
WP_CLI::error( $r );
448+
if ( is_wp_error( $result ) ) {
449+
WP_CLI::error( $result );
450450
} else {
451451
WP_CLI::success( "$success comment $comment->comment_ID." );
452452
}

src/Menu_Item_Command.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ public function delete( $args, $_ ) {
370370
foreach ( $args as $arg ) {
371371

372372
$parent_menu_id = (int) get_post_meta( $arg, '_menu_item_menu_item_parent', true );
373-
$ret = wp_delete_post( $arg, true );
374-
if ( ! $ret ) {
373+
$result = wp_delete_post( $arg, true );
374+
if ( ! $result ) {
375375
WP_CLI::warning( "Couldn't delete menu item {$arg}." );
376376
$errors++;
377377
} elseif ( $parent_menu_id ) {
@@ -387,7 +387,7 @@ public function delete( $args, $_ ) {
387387
}
388388

389389
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Will increase count for non existent menu.
390-
if ( false != $ret ) {
390+
if ( false != $result ) {
391391
$count++;
392392
}
393393
}
@@ -465,11 +465,11 @@ private function add_or_update_item( $method, $type, $args, $assoc_args ) {
465465
}
466466

467467
$menu_item_args['menu-item-type'] = $type;
468-
$ret = wp_update_nav_menu_item( $menu->term_id, $menu_item_db_id, $menu_item_args );
468+
$result = wp_update_nav_menu_item( $menu->term_id, $menu_item_db_id, $menu_item_args );
469469

470-
if ( is_wp_error( $ret ) ) {
471-
WP_CLI::error( $ret->get_error_message() );
472-
} elseif ( ! $ret ) {
470+
if ( is_wp_error( $result ) ) {
471+
WP_CLI::error( $result->get_error_message() );
472+
} elseif ( ! $result ) {
473473
if ( 'add' === $method ) {
474474
WP_CLI::error( "Couldn't add menu item." );
475475
} elseif ( 'update' === $method ) {
@@ -486,12 +486,12 @@ private function add_or_update_item( $method, $type, $args, $assoc_args ) {
486486
*
487487
* @see https://core.trac.wordpress.org/ticket/27113
488488
*/
489-
if ( ! is_object_in_term( $ret, 'nav_menu', (int) $menu->term_id ) ) {
490-
wp_set_object_terms( $ret, [ (int) $menu->term_id ], 'nav_menu' );
489+
if ( ! is_object_in_term( $result, 'nav_menu', (int) $menu->term_id ) ) {
490+
wp_set_object_terms( $result, [ (int) $menu->term_id ], 'nav_menu' );
491491
}
492492

493493
if ( 'add' === $method && ! empty( $assoc_args['porcelain'] ) ) {
494-
WP_CLI::line( $ret );
494+
WP_CLI::line( $result );
495495
} else {
496496
if ( 'add' === $method ) {
497497
WP_CLI::success( 'Menu item added.' );

src/Option_Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ function( $key ) {
510510

511511
try {
512512
$value = $traverser->get( $key_path );
513-
} catch ( Exception $e ) {
513+
} catch ( Exception $exception ) {
514514
die( 1 );
515515
}
516516

@@ -583,8 +583,8 @@ function( $key ) {
583583

584584
try {
585585
$traverser->$action( $key_path, $patch_value );
586-
} catch ( Exception $e ) {
587-
WP_CLI::error( $e->getMessage() );
586+
} catch ( Exception $exception ) {
587+
WP_CLI::error( $exception->getMessage() );
588588
}
589589

590590
$patched_value = sanitize_option( $key, $traverser->value() );

src/Post_Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ function ( $params ) {
373373
public function edit( $args, $_ ) {
374374
$post = $this->fetcher->get_check( $args[0] );
375375

376-
$r = $this->_edit( $post->post_content, "WP-CLI post {$post->ID}" );
376+
$result = $this->_edit( $post->post_content, "WP-CLI post {$post->ID}" );
377377

378-
if ( false === $r ) {
378+
if ( false === $result ) {
379379
WP_CLI::warning( 'No change made to post content.', 'Aborted' );
380380
} else {
381-
$this->update( $args, [ 'post_content' => $r ] );
381+
$this->update( $args, [ 'post_content' => $result ] );
382382
}
383383
}
384384

src/Site_Command.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,24 +580,25 @@ public function list_( $_, $assoc_args ) {
580580
'where' => $where,
581581
'append' => $append,
582582
];
583-
$it = new TableIterator( $iterator_args );
584583

585-
$it = Utils\iterator_map(
586-
$it,
584+
$iterator = new TableIterator( $iterator_args );
585+
586+
$iterator = Utils\iterator_map(
587+
$iterator,
587588
function( $blog ) {
588589
$blog->url = trailingslashit( get_site_url( $blog->blog_id ) );
589590
return $blog;
590591
}
591592
);
592593

593594
if ( ! empty( $assoc_args['format'] ) && 'ids' === $assoc_args['format'] ) {
594-
$sites = iterator_to_array( $it );
595+
$sites = iterator_to_array( $iterator );
595596
$ids = wp_list_pluck( $sites, 'blog_id' );
596597
$formatter = new Formatter( $assoc_args, null, 'site' );
597598
$formatter->display_items( $ids );
598599
} else {
599600
$formatter = new Formatter( $assoc_args, null, 'site' );
600-
$formatter->display_items( $it );
601+
$formatter->display_items( $iterator );
601602
}
602603
}
603604

src/Site_Option_Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ function( $key ) {
320320

321321
try {
322322
$value = $traverser->get( $key_path );
323-
} catch ( Exception $e ) {
323+
} catch ( Exception $exception ) {
324324
die( 1 );
325325
}
326326

@@ -393,8 +393,8 @@ function( $key ) {
393393

394394
try {
395395
$traverser->$action( $key_path, $patch_value );
396-
} catch ( Exception $e ) {
397-
WP_CLI::error( $e->getMessage() );
396+
} catch ( Exception $exception ) {
397+
WP_CLI::error( $exception->getMessage() );
398398
}
399399

400400
$patched_value = sanitize_option( $key, $traverser->value() );

src/Term_Command.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ public function create( $args, $assoc_args ) {
221221

222222
$assoc_args = wp_slash( $assoc_args );
223223
$term = wp_slash( $term );
224-
$ret = wp_insert_term( $term, $taxonomy, $assoc_args );
224+
$result = wp_insert_term( $term, $taxonomy, $assoc_args );
225225

226-
if ( is_wp_error( $ret ) ) {
227-
WP_CLI::error( $ret->get_error_message() );
226+
if ( is_wp_error( $result ) ) {
227+
WP_CLI::error( $result->get_error_message() );
228228
} else {
229229
if ( $porcelain ) {
230-
WP_CLI::line( $ret['term_id'] );
230+
WP_CLI::line( $result['term_id'] );
231231
} else {
232-
WP_CLI::success( sprintf( 'Created %s %d.', $taxonomy, $ret['term_id'] ) );
232+
WP_CLI::success( sprintf( 'Created %s %d.', $taxonomy, $result['term_id'] ) );
233233
}
234234
}
235235
}
@@ -374,10 +374,10 @@ public function update( $args, $assoc_args ) {
374374
}
375375

376376
// Update term.
377-
$ret = wp_update_term( $term->term_id, $taxonomy, $assoc_args );
377+
$result = wp_update_term( $term->term_id, $taxonomy, $assoc_args );
378378

379-
if ( is_wp_error( $ret ) ) {
380-
WP_CLI::error( $ret->get_error_message() );
379+
if ( is_wp_error( $result ) ) {
380+
WP_CLI::error( $result->get_error_message() );
381381
} else {
382382
WP_CLI::success( 'Term updated.' );
383383
}
@@ -451,12 +451,12 @@ public function delete( $args, $assoc_args ) {
451451

452452
}
453453

454-
$ret = wp_delete_term( $term_id, $taxonomy );
454+
$result = wp_delete_term( $term_id, $taxonomy );
455455

456-
if ( is_wp_error( $ret ) ) {
457-
WP_CLI::warning( $ret );
456+
if ( is_wp_error( $result ) ) {
457+
WP_CLI::warning( $result );
458458
$errors++;
459-
} elseif ( $ret ) {
459+
} elseif ( $result ) {
460460
WP_CLI::log( sprintf( 'Deleted %s %d.', $taxonomy, $term_id ) );
461461
$successes++;
462462
} else {

src/User_Command.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function list_( $args, $assoc_args ) {
169169
} elseif ( 'count' === $formatter->format ) {
170170
$formatter->display_items( $users );
171171
} else {
172-
$it = Utils\iterator_map(
172+
$iterator = Utils\iterator_map(
173173
$users,
174174
function ( $user ) {
175175
if ( ! is_object( $user ) ) {
@@ -182,7 +182,7 @@ function ( $user ) {
182182
}
183183
);
184184

185-
$formatter->display_items( $it );
185+
$formatter->display_items( $iterator );
186186
}
187187
}
188188

@@ -282,14 +282,14 @@ function ( $user ) use ( $network, $reassign ) {
282282
$user_id = $user->ID;
283283

284284
if ( $network ) {
285-
$r = wpmu_delete_user( $user_id );
285+
$result = wpmu_delete_user( $user_id );
286286
$message = "Deleted user {$user_id}.";
287287
} else {
288-
$r = wp_delete_user( $user_id, $reassign );
288+
$result = wp_delete_user( $user_id, $reassign );
289289
$message = "Removed user {$user_id} from " . home_url() . '.';
290290
}
291291

292-
if ( $r ) {
292+
if ( $result ) {
293293
return [ 'success', $message ];
294294
} else {
295295
return [ 'error', "Failed deleting user {$user_id}." ];
@@ -405,9 +405,9 @@ public function create( $args, $assoc_args ) {
405405
}
406406

407407
if ( is_multisite() ) {
408-
$ret = wpmu_validate_user_signup( $user->user_login, $user->user_email );
409-
if ( is_wp_error( $ret['errors'] ) && ! empty( $ret['errors']->errors ) ) {
410-
WP_CLI::error( $ret['errors'] );
408+
$result = wpmu_validate_user_signup( $user->user_login, $user->user_email );
409+
if ( is_wp_error( $result['errors'] ) && ! empty( $result['errors']->errors ) ) {
410+
WP_CLI::error( $result['errors'] );
411411
}
412412
$user_id = wpmu_create_user( $user->user_login, $user->user_pass, $user->user_email );
413413
if ( ! $user_id ) {
@@ -1008,9 +1008,9 @@ public function import_csv( $args, $assoc_args ) {
10081008
unset( $new_user['ID'] ); // Unset else it will just return the ID
10091009

10101010
if ( is_multisite() ) {
1011-
$ret = wpmu_validate_user_signup( $new_user['user_login'], $new_user['user_email'] );
1012-
if ( is_wp_error( $ret['errors'] ) && ! empty( $ret['errors']->errors ) ) {
1013-
WP_CLI::warning( $ret['errors'] );
1011+
$result = wpmu_validate_user_signup( $new_user['user_login'], $new_user['user_email'] );
1012+
if ( is_wp_error( $result['errors'] ) && ! empty( $result['errors']->errors ) ) {
1013+
WP_CLI::warning( $result['errors'] );
10141014
continue;
10151015
}
10161016
$user_id = wpmu_create_user( $new_user['user_login'], $new_user['user_pass'], $new_user['user_email'] );

src/WP_CLI/CommandWithDBObject.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use WP_CLI;
66
use WP_CLI_Command;
77
use WP_CLI\Utils;
8+
use WP_Error;
89

910
/**
1011
* Base class for WP-CLI commands that deal with database objects.
@@ -120,8 +121,8 @@ protected function _delete( $args, $assoc_args, $callback ) {
120121
}
121122

122123
foreach ( $args as $obj_id ) {
123-
$r = $callback( $obj_id, $assoc_args );
124-
$status = $this->success_or_failure( $r );
124+
$result = $callback( $obj_id, $assoc_args );
125+
$status = $this->success_or_failure( $result );
125126
}
126127

127128
if ( Utils\get_flag_value( $assoc_args, 'defer-term-counting' ) ) {
@@ -134,13 +135,13 @@ protected function _delete( $args, $assoc_args, $callback ) {
134135
/**
135136
* Format callback response to consistent format.
136137
*
137-
* @param WP_Error|true $r Response from CRUD callback.
138-
* @param string $success_msg
138+
* @param WP_Error|true $response Response from CRUD callback.
139+
* @param string $success_msg
139140
* @return array
140141
*/
141-
protected function wp_error_to_resp( $r, $success_msg ) {
142-
if ( is_wp_error( $r ) ) {
143-
return [ 'error', $r->get_error_message() ];
142+
protected function wp_error_to_resp( $response, $success_msg ) {
143+
if ( is_wp_error( $response ) ) {
144+
return [ 'error', $response->get_error_message() ];
144145
} else {
145146
return [ 'success', $success_msg ];
146147
}
@@ -149,11 +150,11 @@ protected function wp_error_to_resp( $r, $success_msg ) {
149150
/**
150151
* Display success or warning based on response; return proper exit code.
151152
*
152-
* @param array $r Formatted from a CRUD callback.
153+
* @param array $response Formatted from a CRUD callback.
153154
* @return int $status
154155
*/
155-
protected function success_or_failure( $r ) {
156-
list( $type, $msg ) = $r;
156+
protected function success_or_failure( $response ) {
157+
list( $type, $msg ) = $response;
157158

158159
if ( 'success' === $type ) {
159160
WP_CLI::success( $msg );

src/WP_CLI/CommandWithMeta.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function ( $key ) {
347347

348348
try {
349349
$value = $traverser->get( $key_path );
350-
} catch ( Exception $e ) {
350+
} catch ( Exception $exception ) {
351351
die( 1 );
352352
}
353353

@@ -424,8 +424,8 @@ function( $key ) {
424424

425425
try {
426426
$traverser->$action( $key_path, $patch_value );
427-
} catch ( Exception $e ) {
428-
WP_CLI::error( $e->getMessage() );
427+
} catch ( Exception $exception ) {
428+
WP_CLI::error( $exception->getMessage() );
429429
}
430430

431431
$patched_meta_value = sanitize_meta( $meta_key, $traverser->value(), $this->meta_type );

0 commit comments

Comments
 (0)