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

Merged
merged 8 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 @@ -21,7 +21,7 @@
"wp-cli/extension-command": "^1.2 || ^2",
"wp-cli/import-command": "^1 || ^2",
"wp-cli/media-command": "^1 || ^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 export-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
return;
}

$wpcli_export_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
$wpcli_export_autoloader = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $wpcli_export_autoloader ) ) {
require_once $wpcli_export_autoloader;
}
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@


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

Expand Down
14 changes: 7 additions & 7 deletions src/Export_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,20 @@ private function check_max_file_size( $size ) {
return true;
}

private function check_include_once( $include_once ) {
if ( null === $include_once ) {
private function check_include_once( $once ) {
if ( null === $once ) {
return true;
}

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

$this->include_once = $include_once;
$this->include_once = $once;

return true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/WP_Export_Oxymel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public function optional_cdata( $tag_name, $contents ) {

public function cdata( $text ) {
if ( is_string( $text ) && ! seems_utf8( $text ) ) {
$text = utf8_encode( $text );
$text = mb_convert_encoding( $text, 'UTF-8' );
}
return parent::cdata( $text );
}
}

8 changes: 4 additions & 4 deletions src/WP_Export_Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public function custom_taxonomies_terms() {
return [];
}
$custom_taxonomies = get_taxonomies( [ '_builtin' => false ] );
$custom_terms = (array) get_terms( $custom_taxonomies, [ 'get' => 'all' ] );
// phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found -- Deprecated, but we need to support older versions of WordPress.
$custom_terms = (array) get_terms( $custom_taxonomies, [ 'get' => 'all' ] );
$this->check_for_orphaned_terms( $custom_terms );
$custom_terms = self::topologically_sort_terms( $custom_terms );
return $custom_terms;
Expand Down Expand Up @@ -305,7 +306,7 @@ private function include_attachment_ids( $post_ids ) {
return [];
}
$attachment_ids = [];
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Assigment is part of the break condition.
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Assigment is part of the break condition.
while ( $batch_of_post_ids = array_splice( $post_ids, 0, self::QUERY_CHUNK ) ) {
$post_parent_condition = _wp_export_build_IN_condition( 'post_parent', $batch_of_post_ids );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped in wpcli_export_build_in_condition() function.
Expand Down Expand Up @@ -344,7 +345,7 @@ private function find_category_from_any_object( $category ) {

private static function topologically_sort_terms( $terms ) {
$sorted = [];
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- assignment is used as break condition.
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- assignment is used as break condition.
while ( $term = array_shift( $terms ) ) {
if ( 0 === (int) $term->parent || isset( $sorted[ $term->parent ] ) ) {
$sorted[ $term->term_id ] = $term;
Expand Down Expand Up @@ -413,4 +414,3 @@ private function get_comments_for_post( $post ) {
return $comments;
}
}

3 changes: 1 addition & 2 deletions src/WP_Export_Split_Files_Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ private function close_current_file() {

private function next_file_name() {
$next_file_name = sprintf( $this->filename_template, $this->next_file_number );
$this->next_file_number++;
++$this->next_file_number;
return $next_file_name;
}

private function next_file_path() {
return untrailingslashit( $this->destination_directory ) . DIRECTORY_SEPARATOR . $this->next_file_name();
}

}
1 change: 0 additions & 1 deletion src/WP_Export_WXR_Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function header() {
)
->open_channel
->to_string();

}

public function site_metadata() {
Expand Down
4 changes: 2 additions & 2 deletions src/WP_Post_IDs_Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function key() {
}

public function next() {
$this->index_in_results++;
$this->global_index++;
++$this->index_in_results;
++$this->global_index;
}

public function rewind() {
Expand Down
Loading