From 3a8b697624c996b3b7c56c58a32887686657e240 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 30 Aug 2023 15:19:29 +0200 Subject: [PATCH 1/5] Update to wp-cli-tests v4 (which requires WPCS v3) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4df73d02..55fceba2 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "wp-cli/db-command": "^1.3 || ^2", "wp-cli/entity-command": "^1.3 || ^2", "wp-cli/extension-command": "^1.2 || ^2", - "wp-cli/wp-cli-tests": "^3.1" + "wp-cli/wp-cli-tests": "^4" }, "config": { "process-timeout": 7200, From 9325a71217540112ee8ce81364eb548b9f2c0f85 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 30 Aug 2023 15:25:01 +0200 Subject: [PATCH 2/5] Fix all autofixable CS issues --- search-replace-command.php | 2 +- src/Search_Replace_Command.php | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/search-replace-command.php b/search-replace-command.php index c7234438..bd2ad0e9 100644 --- a/search-replace-command.php +++ b/search-replace-command.php @@ -4,7 +4,7 @@ return; } -$wpcli_search_replace_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; +$wpcli_search_replace_autoloader = __DIR__ . '/vendor/autoload.php'; if ( file_exists( $wpcli_search_replace_autoloader ) ) { require_once $wpcli_search_replace_autoloader; } diff --git a/src/Search_Replace_Command.php b/src/Search_Replace_Command.php index cba190a4..6b8ac19c 100644 --- a/src/Search_Replace_Command.php +++ b/src/Search_Replace_Command.php @@ -249,7 +249,7 @@ public function __invoke( $args, $assoc_args ) { } $export_insert_size = Utils\get_flag_value( $assoc_args, 'export_insert_size', 50 ); // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- See the code, this is deliberate. - if ( (int) $export_insert_size == $export_insert_size && $export_insert_size > 0 ) { + if ( (int) $export_insert_size === $export_insert_size && $export_insert_size > 0 ) { $this->export_insert_size = $export_insert_size; } $php_only = true; @@ -473,7 +473,7 @@ private function php_export_table( $table, $old, $new ) { if ( $value && ! in_array( $col, $primary_keys, true ) && ! in_array( $col, $this->skip_columns, true ) ) { $new_value = $replacer->run( $value ); if ( $new_value !== $value ) { - $col_counts[ $col ]++; + ++$col_counts[ $col ]; $value = $new_value; } } @@ -491,7 +491,7 @@ private function php_export_table( $table, $old, $new ) { $table_report[] = array( $table, $col, $col_count, 'PHP' ); } if ( $col_count ) { - $total_cols++; + ++$total_cols; $total_rows += $col_count; } } @@ -590,7 +590,7 @@ static function ( $key ) { $replacer->clear_log_data(); } - $count++; + ++$count; if ( ! $this->dry_run ) { $update_where = array(); foreach ( (array) $keys as $k => $v ) { @@ -682,10 +682,10 @@ private function write_sql_row_fields( $table, $rows ) { // Add new insert statement if needed. Before this we close the previous with semicolon and write statement to sql-file. // "Statement break" is needed: - // 1. When the loop is running every nth time (where n is insert statement size, $export_index_size). Remainder is zero also on first round, so it have to be excluded. - // $index % $export_insert_size == 0 && $index > 0 - // 2. Or when the loop is running last time - // $index == $count + // 1. When the loop is running every nth time (where n is insert statement size, $export_index_size). Remainder is zero also on first round, so it have to be excluded. + // $index % $export_insert_size == 0 && $index > 0 + // 2. Or when the loop is running last time + // $index == $count if ( ( 0 === $index % $export_insert_size && $index > 0 ) || $index === $count ) { $sql .= ";\n"; @@ -710,7 +710,7 @@ private function write_sql_row_fields( $table, $rows ) { $sql .= ",\n"; } - $index++; + ++$index; } } @@ -1043,5 +1043,4 @@ private function log_write( $col, $keys, $table, $old_bits, $new_bits ) { fwrite( $this->log_handle, "{$table_column_id_log}\n{$old_log}\n{$new_log}\n" ); } - } From 3ae41fb326d8e231ff27d37534994ae75e48688c Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 1 Sep 2023 05:17:44 -0700 Subject: [PATCH 3/5] Restore loose comparison --- src/Search_Replace_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Search_Replace_Command.php b/src/Search_Replace_Command.php index 6b8ac19c..a8470e03 100644 --- a/src/Search_Replace_Command.php +++ b/src/Search_Replace_Command.php @@ -248,8 +248,8 @@ public function __invoke( $args, $assoc_args ) { } } $export_insert_size = Utils\get_flag_value( $assoc_args, 'export_insert_size', 50 ); - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- See the code, this is deliberate. - if ( (int) $export_insert_size === $export_insert_size && $export_insert_size > 0 ) { + // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- See the code, this is deliberate. + if ( (int) $export_insert_size == $export_insert_size && $export_insert_size > 0 ) { $this->export_insert_size = $export_insert_size; } $php_only = true; From bafd97848097cf717ca3067bbf6e0af0583af8b3 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 1 Sep 2023 05:23:38 -0700 Subject: [PATCH 4/5] Change property name --- phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 23ed3f41..c15144cb 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -68,7 +68,7 @@ Related: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1623 --> - + From dfbea9510f95f93534f4babec819332611b375e5 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 1 Sep 2023 05:29:58 -0700 Subject: [PATCH 5/5] Allow `$new` to prevent code churn --- phpcs.xml.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c15144cb..daafcfad 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -32,6 +32,8 @@ + +