Skip to content

Commit 0b662a3

Browse files
Update to WPCS v3 (#188)
* Update to wp-cli-tests v4 (which requires WPCS v3) * Fix all autofixable CS issues * Restore loose comparison * Change property name * Allow `$new` to prevent code churn --------- Co-authored-by: Daniel Bachhuber <[email protected]>
1 parent c6c6501 commit 0b662a3

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"wp-cli/db-command": "^1.3 || ^2",
1919
"wp-cli/entity-command": "^1.3 || ^2",
2020
"wp-cli/extension-command": "^1.2 || ^2",
21-
"wp-cli/wp-cli-tests": "^3.1"
21+
"wp-cli/wp-cli-tests": "^4"
2222
},
2323
"config": {
2424
"process-timeout": 7200,

phpcs.xml.dist

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<!-- Can't be helped as WP itself uses these functions for the data being adjusted. -->
3333
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize"/>
3434
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize"/>
35+
<!-- Allow $new as an argument to mitigate code churn -->
36+
<exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames.newFound" />
3537
</rule>
3638

3739
<!--
@@ -68,7 +70,7 @@
6870
Related: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1623 -->
6971
<rule ref="WordPress.NamingConventions.ValidVariableName">
7072
<properties>
71-
<property name="customPropertiesWhitelist" type="array">
73+
<property name="allowed_custom_properties" type="array">
7274
<element value="Key"/>
7375
<element value="Field"/>
7476
<element value="Type"/>

search-replace-command.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
return;
55
}
66

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

src/Search_Replace_Command.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function __invoke( $args, $assoc_args ) {
248248
}
249249
}
250250
$export_insert_size = Utils\get_flag_value( $assoc_args, 'export_insert_size', 50 );
251-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- See the code, this is deliberate.
251+
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- See the code, this is deliberate.
252252
if ( (int) $export_insert_size == $export_insert_size && $export_insert_size > 0 ) {
253253
$this->export_insert_size = $export_insert_size;
254254
}
@@ -473,7 +473,7 @@ private function php_export_table( $table, $old, $new ) {
473473
if ( $value && ! in_array( $col, $primary_keys, true ) && ! in_array( $col, $this->skip_columns, true ) ) {
474474
$new_value = $replacer->run( $value );
475475
if ( $new_value !== $value ) {
476-
$col_counts[ $col ]++;
476+
++$col_counts[ $col ];
477477
$value = $new_value;
478478
}
479479
}
@@ -491,7 +491,7 @@ private function php_export_table( $table, $old, $new ) {
491491
$table_report[] = array( $table, $col, $col_count, 'PHP' );
492492
}
493493
if ( $col_count ) {
494-
$total_cols++;
494+
++$total_cols;
495495
$total_rows += $col_count;
496496
}
497497
}
@@ -590,7 +590,7 @@ static function ( $key ) {
590590
$replacer->clear_log_data();
591591
}
592592

593-
$count++;
593+
++$count;
594594
if ( ! $this->dry_run ) {
595595
$update_where = array();
596596
foreach ( (array) $keys as $k => $v ) {
@@ -682,10 +682,10 @@ private function write_sql_row_fields( $table, $rows ) {
682682

683683
// Add new insert statement if needed. Before this we close the previous with semicolon and write statement to sql-file.
684684
// "Statement break" is needed:
685-
// 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.
686-
// $index % $export_insert_size == 0 && $index > 0
687-
// 2. Or when the loop is running last time
688-
// $index == $count
685+
// 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.
686+
// $index % $export_insert_size == 0 && $index > 0
687+
// 2. Or when the loop is running last time
688+
// $index == $count
689689
if ( ( 0 === $index % $export_insert_size && $index > 0 ) || $index === $count ) {
690690
$sql .= ";\n";
691691

@@ -710,7 +710,7 @@ private function write_sql_row_fields( $table, $rows ) {
710710
$sql .= ",\n";
711711
}
712712

713-
$index++;
713+
++$index;
714714
}
715715
}
716716

@@ -1043,5 +1043,4 @@ private function log_write( $col, $keys, $table, $old_bits, $new_bits ) {
10431043

10441044
fwrite( $this->log_handle, "{$table_column_id_log}\n{$old_log}\n{$new_log}\n" );
10451045
}
1046-
10471046
}

0 commit comments

Comments
 (0)