Skip to content

Commit 17b1654

Browse files
authored
Merge pull request #373 from wp-cli/fix/wpcs-3.0-issues
2 parents b96e959 + d5275f3 commit 17b1654

13 files changed

+34
-44
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"wp-cli/entity-command": "^1.3 || ^2",
2626
"wp-cli/language-command": "^2.0",
2727
"wp-cli/scaffold-command": "^1.2 || ^2",
28-
"wp-cli/wp-cli-tests": "^3.1"
28+
"wp-cli/wp-cli-tests": "^4"
2929
},
3030
"config": {
3131
"process-timeout": 7200,

extension-command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
return;
55
}
66

7-
$wpcli_extension_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
7+
$wpcli_extension_autoloader = __DIR__ . '/vendor/autoload.php';
88
if ( file_exists( $wpcli_extension_autoloader ) ) {
99
require_once $wpcli_extension_autoloader;
1010
}

src/Plugin_AutoUpdates_Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ public function enable( $args, $assoc_args ) {
9999
continue;
100100
}
101101

102-
$count++;
102+
++$count;
103103

104104
if ( $enabled ) {
105105
WP_CLI::warning(
106106
"Auto-updates already enabled for plugin {$plugin->name}."
107107
);
108108
} else {
109109
$auto_updates[] = $plugin->file;
110-
$successes++;
110+
++$successes;
111111
}
112112
}
113113

@@ -176,15 +176,15 @@ public function disable( $args, $assoc_args ) {
176176
continue;
177177
}
178178

179-
$count++;
179+
++$count;
180180

181181
if ( ! $enabled ) {
182182
WP_CLI::warning(
183183
"Auto-updates already disabled for plugin {$plugin->name}."
184184
);
185185
} else {
186186
$auto_updates = array_diff( $auto_updates, [ $plugin->file ] );
187-
$successes++;
187+
++$successes;
188188
}
189189
}
190190

src/Plugin_Command.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,14 @@ public function activate( $args, $assoc_args = array() ) {
357357
WP_CLI::warning( "Failed to activate plugin. {$message}" );
358358
} else {
359359
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
360-
$successes++;
360+
++$successes;
361361
}
362362
}
363363

364364
if ( ! $this->chained_command ) {
365365
$verb = $network_wide ? 'network activate' : 'activate';
366366
Utils\report_batch_operation_results( 'plugin', $verb, count( $args ), $successes, $errors );
367367
}
368-
369368
}
370369

371370
/**
@@ -428,7 +427,7 @@ public function deactivate( $args, $assoc_args = array() ) {
428427
// Network active plugins must be explicitly deactivated.
429428
if ( ! $network_wide && 'active-network' === $status ) {
430429
WP_CLI::warning( "Plugin '{$plugin->name}' is network active and must be deactivated with --network flag." );
431-
$errors++;
430+
++$errors;
432431
continue;
433432
}
434433

@@ -452,7 +451,7 @@ public function deactivate( $args, $assoc_args = array() ) {
452451
}
453452

454453
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'deactivate' );
455-
$successes++;
454+
++$successes;
456455

457456
if ( Utils\get_flag_value( $assoc_args, 'uninstall' ) ) {
458457
WP_CLI::log( "Uninstalling '{$plugin->name}'..." );
@@ -466,7 +465,6 @@ public function deactivate( $args, $assoc_args = array() ) {
466465
$verb = $network_wide ? 'network deactivate' : 'deactivate';
467466
Utils\report_batch_operation_results( 'plugin', $verb, count( $args ), $successes, $errors );
468467
}
469-
470468
}
471469

472470
/**
@@ -511,7 +509,7 @@ public function toggle( $args, $assoc_args = array() ) {
511509
} else {
512510
$this->activate( array( $plugin->name ), $assoc_args );
513511
}
514-
$successes++;
512+
++$successes;
515513
}
516514
$this->chained_command = false;
517515
Utils\report_batch_operation_results( 'plugin', 'toggle', count( $args ), $successes, $errors );
@@ -952,7 +950,7 @@ public function uninstall( $args, $assoc_args = array() ) {
952950
foreach ( $plugins as $plugin ) {
953951
if ( is_plugin_active( $plugin->file ) && ! WP_CLI\Utils\get_flag_value( $assoc_args, 'deactivate' ) ) {
954952
WP_CLI::warning( "The '{$plugin->name}' plugin is active." );
955-
$errors++;
953+
++$errors;
956954
continue;
957955
}
958956

@@ -997,7 +995,7 @@ public function uninstall( $args, $assoc_args = array() ) {
997995
} else {
998996
WP_CLI::log( "Ran uninstall procedure for '$plugin->name' plugin without deleting." );
999997
}
1000-
$successes++;
998+
++$successes;
1001999
}
10021000
if ( ! $this->chained_command ) {
10031001
Utils\report_batch_operation_results( 'plugin', 'uninstall', count( $args ), $successes, $errors );
@@ -1113,9 +1111,9 @@ public function delete( $args, $assoc_args = array() ) {
11131111
foreach ( $this->fetcher->get_many( $args ) as $plugin ) {
11141112
if ( $this->delete_plugin( $plugin ) ) {
11151113
WP_CLI::log( "Deleted '{$plugin->name}' plugin." );
1116-
$successes++;
1114+
++$successes;
11171115
} else {
1118-
$errors++;
1116+
++$errors;
11191117
}
11201118
}
11211119
if ( ! $this->chained_command ) {

src/Theme_AutoUpdates_Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ public function enable( $args, $assoc_args ) {
9999
continue;
100100
}
101101

102-
$count++;
102+
++$count;
103103

104104
if ( $enabled ) {
105105
WP_CLI::warning(
106106
"Auto-updates already enabled for theme {$theme->stylesheet}."
107107
);
108108
} else {
109109
$auto_updates[] = $theme->stylesheet;
110-
$successes++;
110+
++$successes;
111111
}
112112
}
113113

@@ -176,15 +176,15 @@ public function disable( $args, $assoc_args ) {
176176
continue;
177177
}
178178

179-
$count++;
179+
++$count;
180180

181181
if ( ! $enabled ) {
182182
WP_CLI::warning(
183183
"Auto-updates already disabled for theme {$theme->stylesheet}."
184184
);
185185
} else {
186186
$auto_updates = array_diff( $auto_updates, [ $theme->stylesheet ] );
187-
$successes++;
187+
++$successes;
188188
}
189189
}
190190

src/Theme_Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,15 +772,15 @@ public function delete( $args, $assoc_args ) {
772772
if ( $this->is_active_theme( $theme ) && ! $force ) {
773773
if ( ! $all ) {
774774
WP_CLI::warning( "Can't delete the currently active theme: $theme_slug" );
775-
$errors++;
775+
++$errors;
776776
}
777777
continue;
778778
}
779779

780780
if ( $this->is_active_parent_theme( $theme ) && ! $force ) {
781781
if ( ! $all ) {
782782
WP_CLI::warning( "Can't delete the parent of the currently active theme: $theme_slug" );
783-
$errors++;
783+
++$errors;
784784
}
785785
continue;
786786
}
@@ -789,10 +789,10 @@ public function delete( $args, $assoc_args ) {
789789

790790
if ( is_wp_error( $r ) ) {
791791
WP_CLI::warning( $r );
792-
$errors++;
792+
++$errors;
793793
} else {
794794
WP_CLI::log( "Deleted '$theme_slug' theme." );
795-
$successes++;
795+
++$successes;
796796
}
797797
}
798798
if ( ! $this->chained_command ) {

src/Theme_Mod_Command.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ public function get( $args = array(), $assoc_args = array() ) {
128128

129129
$formatter = new \WP_CLI\Formatter( $assoc_args, $this->fields, 'thememods' );
130130
$formatter->display_items( $list );
131-
132131
}
133132

134133
/**
@@ -215,7 +214,6 @@ public function remove( $args = array(), $assoc_args = array() ) {
215214
$count = count( $args );
216215
$success_message = ( 1 === $count ) ? '%d mod removed.' : '%d mods removed.';
217216
WP_CLI::success( sprintf( $success_message, $count ) );
218-
219217
}
220218

221219
/**
@@ -246,5 +244,4 @@ public function set( $args = array(), $assoc_args = array() ) {
246244
WP_CLI::success( "Could not update theme mod {$mod}." );
247245
}
248246
}
249-
250247
}

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct() {
3030
// Do not automatically check translations updates after updating plugins/themes.
3131
add_action(
3232
'upgrader_process_complete',
33-
function() {
33+
function () {
3434
remove_action( 'upgrader_process_complete', [ 'Language_Pack_Upgrader', 'async_upgrade' ], 20 );
3535
},
3636
1
@@ -170,7 +170,7 @@ public function install( $args, $assoc_args ) {
170170
// Don't attempt to rename ZIPs uploaded to the releases page or coming from a raw source.
171171
&& ! preg_match( '#github\.com/[^/]+/[^/]+/(?:releases/download|raw)/#', $slug ) ) {
172172

173-
$filter = function( $source, $remote_source, $upgrader ) use ( $slug ) {
173+
$filter = function ( $source, $remote_source, $upgrader ) use ( $slug ) {
174174

175175
$slug_dir = Utils\basename( $this->parse_url_host_component( $slug, PHP_URL_PATH ), '.zip' );
176176

@@ -202,30 +202,30 @@ public function install( $args, $assoc_args ) {
202202
if ( $filter ) {
203203
remove_filter( 'upgrader_source_selection', $filter, 10 );
204204
}
205-
$successes++;
205+
++$successes;
206206
} else {
207-
$errors++;
207+
++$errors;
208208
}
209209
} else {
210210
// Assume a plugin/theme slug from the WordPress.org repository has been specified.
211211
$result = $this->install_from_repo( $slug, $assoc_args );
212212

213213
if ( is_null( $result ) ) {
214-
$errors++;
214+
++$errors;
215215
} elseif ( is_wp_error( $result ) ) {
216216
$key = $result->get_error_code();
217217
if ( in_array( $key, [ 'plugins_api_failed', 'themes_api_failed' ], true )
218218
&& ! empty( $result->error_data[ $key ] ) && in_array( $result->error_data[ $key ], [ 'N;', 'b:0;' ], true ) ) {
219219
WP_CLI::warning( "Couldn't find '$slug' in the WordPress.org {$this->item_type} directory." );
220-
$errors++;
220+
++$errors;
221221
} else {
222222
WP_CLI::warning( "$slug: " . $result->get_error_message() );
223223
if ( 'already_installed' !== $key ) {
224-
$errors++;
224+
++$errors;
225225
}
226226
}
227227
} else {
228-
$successes++;
228+
++$successes;
229229
}
230230
}
231231

@@ -381,7 +381,7 @@ protected function update_many( $args, $assoc_args ) {
381381
foreach ( $items_to_update as $item_key => $item_info ) {
382382
if ( static::INVALID_VERSION_MESSAGE === $item_info['update'] ) {
383383
WP_CLI::warning( "{$item_info['name']}: " . static::INVALID_VERSION_MESSAGE . '.' );
384-
$skipped++;
384+
++$skipped;
385385
unset( $items_to_update[ $item_key ] );
386386
}
387387
}
@@ -426,7 +426,7 @@ protected function update_many( $args, $assoc_args ) {
426426
}
427427
$upgrader = $this->get_upgrader( $assoc_args );
428428
// Ensure the upgrader uses the download offer present in each item.
429-
$transient_filter = function( $transient ) use ( $items_to_update ) {
429+
$transient_filter = function ( $transient ) use ( $items_to_update ) {
430430
foreach ( $items_to_update as $name => $item_data ) {
431431
if ( isset( $transient->response[ $name ] ) ) {
432432
$transient->response[ $name ]->new_version = $item_data['update_version'];
@@ -467,7 +467,7 @@ static function ( $result ) {
467467
'status' => ( null !== $result[ $info['update_id'] ] && ! is_wp_error( $result[ $info['update_id'] ] ) ) ? 'Updated' : 'Error',
468468
];
469469
if ( null === $result[ $info['update_id'] ] || is_wp_error( $result[ $info['update_id'] ] ) ) {
470-
$errors++;
470+
++$errors;
471471
}
472472
}
473473

@@ -767,5 +767,4 @@ private function parse_url_host_component( $url, $component ) {
767767
// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- parse_url will only be used in absence of wp_parse_url.
768768
return function_exists( 'wp_parse_url' ) ? wp_parse_url( $url, $component ) : parse_url( $url, $component );
769769
}
770-
771770
}

src/WP_CLI/DestructivePluginUpgrader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ public function install_package( $args = array() ) {
1515
return parent::install_package( $args );
1616
}
1717
}
18-

src/WP_CLI/DestructiveThemeUpgrader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ public function install_package( $args = array() ) {
1515
return parent::install_package( $args );
1616
}
1717
}
18-

0 commit comments

Comments
 (0)