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 #373

Merged
merged 2 commits into from
Aug 30, 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 @@ -25,7 +25,7 @@
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/language-command": "^2.0",
"wp-cli/scaffold-command": "^1.2 || ^2",
"wp-cli/wp-cli-tests": "^3.1"
"wp-cli/wp-cli-tests": "^4"
},
"config": {
"process-timeout": 7200,
Expand Down
2 changes: 1 addition & 1 deletion extension-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
return;
}

$wpcli_extension_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
$wpcli_extension_autoloader = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $wpcli_extension_autoloader ) ) {
require_once $wpcli_extension_autoloader;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Plugin_AutoUpdates_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public function enable( $args, $assoc_args ) {
continue;
}

$count++;
++$count;

if ( $enabled ) {
WP_CLI::warning(
"Auto-updates already enabled for plugin {$plugin->name}."
);
} else {
$auto_updates[] = $plugin->file;
$successes++;
++$successes;
}
}

Expand Down Expand Up @@ -176,15 +176,15 @@ public function disable( $args, $assoc_args ) {
continue;
}

$count++;
++$count;

if ( ! $enabled ) {
WP_CLI::warning(
"Auto-updates already disabled for plugin {$plugin->name}."
);
} else {
$auto_updates = array_diff( $auto_updates, [ $plugin->file ] );
$successes++;
++$successes;
}
}

Expand Down
18 changes: 8 additions & 10 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,14 @@ public function activate( $args, $assoc_args = array() ) {
WP_CLI::warning( "Failed to activate plugin. {$message}" );
} else {
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
$successes++;
++$successes;
}
}

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

}

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

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

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

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

}

/**
Expand Down Expand Up @@ -511,7 +509,7 @@ public function toggle( $args, $assoc_args = array() ) {
} else {
$this->activate( array( $plugin->name ), $assoc_args );
}
$successes++;
++$successes;
}
$this->chained_command = false;
Utils\report_batch_operation_results( 'plugin', 'toggle', count( $args ), $successes, $errors );
Expand Down Expand Up @@ -952,7 +950,7 @@ public function uninstall( $args, $assoc_args = array() ) {
foreach ( $plugins as $plugin ) {
if ( is_plugin_active( $plugin->file ) && ! WP_CLI\Utils\get_flag_value( $assoc_args, 'deactivate' ) ) {
WP_CLI::warning( "The '{$plugin->name}' plugin is active." );
$errors++;
++$errors;
continue;
}

Expand Down Expand Up @@ -997,7 +995,7 @@ public function uninstall( $args, $assoc_args = array() ) {
} else {
WP_CLI::log( "Ran uninstall procedure for '$plugin->name' plugin without deleting." );
}
$successes++;
++$successes;
}
if ( ! $this->chained_command ) {
Utils\report_batch_operation_results( 'plugin', 'uninstall', count( $args ), $successes, $errors );
Expand Down Expand Up @@ -1113,9 +1111,9 @@ public function delete( $args, $assoc_args = array() ) {
foreach ( $this->fetcher->get_many( $args ) as $plugin ) {
if ( $this->delete_plugin( $plugin ) ) {
WP_CLI::log( "Deleted '{$plugin->name}' plugin." );
$successes++;
++$successes;
} else {
$errors++;
++$errors;
}
}
if ( ! $this->chained_command ) {
Expand Down
8 changes: 4 additions & 4 deletions src/Theme_AutoUpdates_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public function enable( $args, $assoc_args ) {
continue;
}

$count++;
++$count;

if ( $enabled ) {
WP_CLI::warning(
"Auto-updates already enabled for theme {$theme->stylesheet}."
);
} else {
$auto_updates[] = $theme->stylesheet;
$successes++;
++$successes;
}
}

Expand Down Expand Up @@ -176,15 +176,15 @@ public function disable( $args, $assoc_args ) {
continue;
}

$count++;
++$count;

if ( ! $enabled ) {
WP_CLI::warning(
"Auto-updates already disabled for theme {$theme->stylesheet}."
);
} else {
$auto_updates = array_diff( $auto_updates, [ $theme->stylesheet ] );
$successes++;
++$successes;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,15 +772,15 @@ public function delete( $args, $assoc_args ) {
if ( $this->is_active_theme( $theme ) && ! $force ) {
if ( ! $all ) {
WP_CLI::warning( "Can't delete the currently active theme: $theme_slug" );
$errors++;
++$errors;
}
continue;
}

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

if ( is_wp_error( $r ) ) {
WP_CLI::warning( $r );
$errors++;
++$errors;
} else {
WP_CLI::log( "Deleted '$theme_slug' theme." );
$successes++;
++$successes;
}
}
if ( ! $this->chained_command ) {
Expand Down
3 changes: 0 additions & 3 deletions src/Theme_Mod_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public function get( $args = array(), $assoc_args = array() ) {

$formatter = new \WP_CLI\Formatter( $assoc_args, $this->fields, 'thememods' );
$formatter->display_items( $list );

}

/**
Expand Down Expand Up @@ -215,7 +214,6 @@ public function remove( $args = array(), $assoc_args = array() ) {
$count = count( $args );
$success_message = ( 1 === $count ) ? '%d mod removed.' : '%d mods removed.';
WP_CLI::success( sprintf( $success_message, $count ) );

}

/**
Expand Down Expand Up @@ -246,5 +244,4 @@ public function set( $args = array(), $assoc_args = array() ) {
WP_CLI::success( "Could not update theme mod {$mod}." );
}
}

}
23 changes: 11 additions & 12 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct() {
// Do not automatically check translations updates after updating plugins/themes.
add_action(
'upgrader_process_complete',
function() {
function () {
remove_action( 'upgrader_process_complete', [ 'Language_Pack_Upgrader', 'async_upgrade' ], 20 );
},
1
Expand Down Expand Up @@ -170,7 +170,7 @@ public function install( $args, $assoc_args ) {
// Don't attempt to rename ZIPs uploaded to the releases page or coming from a raw source.
&& ! preg_match( '#github\.com/[^/]+/[^/]+/(?:releases/download|raw)/#', $slug ) ) {

$filter = function( $source, $remote_source, $upgrader ) use ( $slug ) {
$filter = function ( $source, $remote_source, $upgrader ) use ( $slug ) {

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

Expand Down Expand Up @@ -202,30 +202,30 @@ public function install( $args, $assoc_args ) {
if ( $filter ) {
remove_filter( 'upgrader_source_selection', $filter, 10 );
}
$successes++;
++$successes;
} else {
$errors++;
++$errors;
}
} else {
// Assume a plugin/theme slug from the WordPress.org repository has been specified.
$result = $this->install_from_repo( $slug, $assoc_args );

if ( is_null( $result ) ) {
$errors++;
++$errors;
} elseif ( is_wp_error( $result ) ) {
$key = $result->get_error_code();
if ( in_array( $key, [ 'plugins_api_failed', 'themes_api_failed' ], true )
&& ! empty( $result->error_data[ $key ] ) && in_array( $result->error_data[ $key ], [ 'N;', 'b:0;' ], true ) ) {
WP_CLI::warning( "Couldn't find '$slug' in the WordPress.org {$this->item_type} directory." );
$errors++;
++$errors;
} else {
WP_CLI::warning( "$slug: " . $result->get_error_message() );
if ( 'already_installed' !== $key ) {
$errors++;
++$errors;
}
}
} else {
$successes++;
++$successes;
}
}

Expand Down Expand Up @@ -381,7 +381,7 @@ protected function update_many( $args, $assoc_args ) {
foreach ( $items_to_update as $item_key => $item_info ) {
if ( static::INVALID_VERSION_MESSAGE === $item_info['update'] ) {
WP_CLI::warning( "{$item_info['name']}: " . static::INVALID_VERSION_MESSAGE . '.' );
$skipped++;
++$skipped;
unset( $items_to_update[ $item_key ] );
}
}
Expand Down Expand Up @@ -426,7 +426,7 @@ protected function update_many( $args, $assoc_args ) {
}
$upgrader = $this->get_upgrader( $assoc_args );
// Ensure the upgrader uses the download offer present in each item.
$transient_filter = function( $transient ) use ( $items_to_update ) {
$transient_filter = function ( $transient ) use ( $items_to_update ) {
foreach ( $items_to_update as $name => $item_data ) {
if ( isset( $transient->response[ $name ] ) ) {
$transient->response[ $name ]->new_version = $item_data['update_version'];
Expand Down Expand Up @@ -467,7 +467,7 @@ static function ( $result ) {
'status' => ( null !== $result[ $info['update_id'] ] && ! is_wp_error( $result[ $info['update_id'] ] ) ) ? 'Updated' : 'Error',
];
if ( null === $result[ $info['update_id'] ] || is_wp_error( $result[ $info['update_id'] ] ) ) {
$errors++;
++$errors;
}
}

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

}
1 change: 0 additions & 1 deletion src/WP_CLI/DestructivePluginUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ public function install_package( $args = array() ) {
return parent::install_package( $args );
}
}

1 change: 0 additions & 1 deletion src/WP_CLI/DestructiveThemeUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ public function install_package( $args = array() ) {
return parent::install_package( $args );
}
}

1 change: 0 additions & 1 deletion src/WP_CLI/Fetchers/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ public function get( $name ) {
return false;
}
}

1 change: 0 additions & 1 deletion src/WP_CLI/Fetchers/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ private function find_inexact_match( $name, $existing_themes ) {
return false;
}
}

2 changes: 1 addition & 1 deletion src/WP_CLI/ParsePluginNameInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function check_optional_args_and_all( $args, $all, $verb = 'install',
$exclude_list = explode( ',', trim( $exclude, ',' ) );
$args = array_filter(
$args,
static function( $slug ) use ( $exclude_list ) {
static function ( $slug ) use ( $exclude_list ) {
return ! in_array( $slug, $exclude_list, true );
}
);
Expand Down