Skip to content

Commit c0dec81

Browse files
Update to WPCS v3 (#110)
* Update to wp-cli-tests v4 (which requires WPCS v3) * Fix all autofixable CS issues * `utf8_encode()` is deprecated in PHP 8.2 * Avoid `$include_once` as a variable name * Restore `wordpress` in filenames * Fix PHPCS issue * Update ignore statement * Ignore deprecation warning --------- Co-authored-by: Daniel Bachhuber <[email protected]>
1 parent b527d8b commit c0dec81

9 files changed

+18
-21
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"wp-cli/extension-command": "^1.2 || ^2",
2222
"wp-cli/import-command": "^1 || ^2",
2323
"wp-cli/media-command": "^1 || ^2",
24-
"wp-cli/wp-cli-tests": "^3.1"
24+
"wp-cli/wp-cli-tests": "^4"
2525
},
2626
"config": {
2727
"process-timeout": 7200,

export-command.php

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

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

phpcs.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565

6666
<!-- Exclude the word `wordpress` from being forced into "trademarked" capitalization in the file names. -->
67-
<rule ref="WordPress.WP.CapitalPDangit.Misspelled">
67+
<rule ref="WordPress.WP.CapitalPDangit.MisspelledInComment">
6868
<exclude-pattern>*/src/Export_Command\.php$</exclude-pattern>
6969
</rule>
7070

src/Export_Command.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,20 @@ private function check_max_file_size( $size ) {
475475
return true;
476476
}
477477

478-
private function check_include_once( $include_once ) {
479-
if ( null === $include_once ) {
478+
private function check_include_once( $once ) {
479+
if ( null === $once ) {
480480
return true;
481481
}
482482

483-
$separator = false !== stripos( $include_once, ' ' ) ? ' ' : ',';
484-
$include_once = array_filter( array_unique( array_map( 'strtolower', explode( $separator, $include_once ) ) ) );
485-
$include_once = array_intersect( $include_once, array( 'categories', 'tags', 'nav_menu_terms', 'custom_taxonomies_terms' ) );
486-
if ( empty( $include_once ) ) {
483+
$separator = false !== stripos( $once, ' ' ) ? ' ' : ',';
484+
$once = array_filter( array_unique( array_map( 'strtolower', explode( $separator, $once ) ) ) );
485+
$once = array_intersect( $once, array( 'categories', 'tags', 'nav_menu_terms', 'custom_taxonomies_terms' ) );
486+
if ( empty( $once ) ) {
487487
WP_CLI::warning( 'include_once should be comma-separated values for optional before_posts sections.' );
488488
return false;
489489
}
490490

491-
$this->include_once = $include_once;
491+
$this->include_once = $once;
492492

493493
return true;
494494
}

src/WP_Export_Oxymel.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ public function optional_cdata( $tag_name, $contents ) {
1717

1818
public function cdata( $text ) {
1919
if ( is_string( $text ) && ! seems_utf8( $text ) ) {
20-
$text = utf8_encode( $text );
20+
$text = mb_convert_encoding( $text, 'UTF-8' );
2121
}
2222
return parent::cdata( $text );
2323
}
2424
}
25-

src/WP_Export_Query.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public function custom_taxonomies_terms() {
120120
return [];
121121
}
122122
$custom_taxonomies = get_taxonomies( [ '_builtin' => false ] );
123-
$custom_terms = (array) get_terms( $custom_taxonomies, [ 'get' => 'all' ] );
123+
// phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found -- Deprecated, but we need to support older versions of WordPress.
124+
$custom_terms = (array) get_terms( $custom_taxonomies, [ 'get' => 'all' ] );
124125
$this->check_for_orphaned_terms( $custom_terms );
125126
$custom_terms = self::topologically_sort_terms( $custom_terms );
126127
return $custom_terms;
@@ -305,7 +306,7 @@ private function include_attachment_ids( $post_ids ) {
305306
return [];
306307
}
307308
$attachment_ids = [];
308-
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Assigment is part of the break condition.
309+
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Assigment is part of the break condition.
309310
while ( $batch_of_post_ids = array_splice( $post_ids, 0, self::QUERY_CHUNK ) ) {
310311
$post_parent_condition = _wp_export_build_IN_condition( 'post_parent', $batch_of_post_ids );
311312
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped in wpcli_export_build_in_condition() function.
@@ -344,7 +345,7 @@ private function find_category_from_any_object( $category ) {
344345

345346
private static function topologically_sort_terms( $terms ) {
346347
$sorted = [];
347-
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- assignment is used as break condition.
348+
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- assignment is used as break condition.
348349
while ( $term = array_shift( $terms ) ) {
349350
if ( 0 === (int) $term->parent || isset( $sorted[ $term->parent ] ) ) {
350351
$sorted[ $term->term_id ] = $term;
@@ -413,4 +414,3 @@ private function get_comments_for_post( $post ) {
413414
return $comments;
414415
}
415416
}
416-

src/WP_Export_Split_Files_Writer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ private function close_current_file() {
9999

100100
private function next_file_name() {
101101
$next_file_name = sprintf( $this->filename_template, $this->next_file_number );
102-
$this->next_file_number++;
102+
++$this->next_file_number;
103103
return $next_file_name;
104104
}
105105

106106
private function next_file_path() {
107107
return untrailingslashit( $this->destination_directory ) . DIRECTORY_SEPARATOR . $this->next_file_name();
108108
}
109-
110109
}

src/WP_Export_WXR_Formatter.php

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public function header() {
8787
)
8888
->open_channel
8989
->to_string();
90-
9190
}
9291

9392
public function site_metadata() {

src/WP_Post_IDs_Iterator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public function key() {
2424
}
2525

2626
public function next() {
27-
$this->index_in_results++;
28-
$this->global_index++;
27+
++$this->index_in_results;
28+
++$this->global_index;
2929
}
3030

3131
public function rewind() {

0 commit comments

Comments
 (0)