Skip to content
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
26 changes: 15 additions & 11 deletions src/Export_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function __invoke( $_, $assoc_args ) {
'wp_export_new_file',
static function ( $file_path ) {
WP_CLI::log( sprintf( 'Writing to file %s', $file_path ) );
Utils\wp_clear_object_cache();
Utils\wp_clear_object_cache(); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.wp_clear_object_cacheDeprecatedRemoved @phpstan-ignore-line
}
);

Expand All @@ -190,15 +190,15 @@ static function ( $file_path ) {
wp_export(
[
'filters' => $this->export_args,
'writer' => 'WP_Export_File_Writer',
'writer' => WP_Export_File_Writer::class, // @phpstan-ignore argument.type
'writer_args' => 'php://output',
]
);
} else {
wp_export(
[
'filters' => $this->export_args,
'writer' => 'WP_Export_Split_Files_Writer',
'writer' => WP_Export_Split_Files_Writer::class, // @phpstan-ignore argument.type
'writer_args' => [
'max_file_size' => $this->max_file_size,
'destination_directory' => $this->wxr_path,
Expand Down Expand Up @@ -234,6 +234,7 @@ private function validate_args( $args ) {

foreach ( $args as $key => $value ) {
if ( is_callable( [ $this, 'check_' . $key ] ) ) {
/** @phpstan-ignore argument.type */
$result = call_user_func( [ $this, 'check_' . $key ], $value );
if ( false === $result ) {
$has_errors = true;
Expand Down Expand Up @@ -281,11 +282,11 @@ private function check_start_date( $date ) {
}

$time = strtotime( $date );
if ( ! empty( $date ) && ! $time ) {
if ( ! empty( $date ) && false === $time ) {
WP_CLI::warning( sprintf( 'The start_date %s is invalid.', $date ) );
return false;
}
$this->export_args['start_date'] = date( 'Y-m-d', $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
$this->export_args['start_date'] = date( 'Y-m-d', (int) $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
return true;
}

Expand All @@ -300,11 +301,11 @@ private function check_end_date( $date ) {
}

$time = strtotime( $date );
if ( ! empty( $date ) && ! $time ) {
if ( ! empty( $date ) && false === $time ) {
WP_CLI::warning( sprintf( 'The end_date %s is invalid.', $date ) );
return false;
}
$this->export_args['end_date'] = date( 'Y-m-d', $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
$this->export_args['end_date'] = date( 'Y-m-d', (int) $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
return true;
}

Expand Down Expand Up @@ -420,8 +421,8 @@ private function check_author( $author ) {
}

// phpcs:ignore WordPress.WP.DeprecatedFunctions.get_users_of_blogFound -- Fallback.
$authors = function_exists( 'get_users' ) ? get_users() : get_users_of_blog();
if ( empty( $authors ) || is_wp_error( $authors ) ) {
$authors = function_exists( 'get_users' ) ? get_users() : get_users_of_blog(); // @phpstan-ignore-line
if ( empty( $authors ) ) {
WP_CLI::warning( 'Could not find any authors in this blog.' );
return false;
}
Expand All @@ -447,6 +448,9 @@ private function check_author( $author ) {
return true;
}

/**
* @phpstan-ignore method.unused
*/
private function check_max_num_posts( $num ) {
if ( null !== $num && ( ! is_numeric( $num ) || $num <= 0 ) ) {
WP_CLI::warning( 'max_num_posts should be a positive integer.' );
Expand All @@ -473,7 +477,7 @@ private function check_category( $category ) {
}

$term = category_exists( $category );
if ( empty( $term ) || is_wp_error( $term ) ) {
if ( empty( $term ) ) {
WP_CLI::warning( sprintf( 'Could not find a category matching %s.', $category ) );
return false;
}
Expand All @@ -492,7 +496,7 @@ private function check_post_status( $status ) {
}

$stati = get_post_stati();
if ( empty( $stati ) || is_wp_error( $stati ) ) {
if ( empty( $stati ) ) {
WP_CLI::warning( 'Could not find any post stati.' );
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WP_Export_Oxymel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function optional( $tag_name, $contents ) {

public function optional_cdata( $tag_name, $contents ) {
if ( $contents ) {
$this->$tag_name->contains->cdata( $contents )->end;
$this->$tag_name->contains->cdata( $contents )->end; // @phpstan-ignore-line
}
return $this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/WP_Export_Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function custom_taxonomies_terms() {
}
$custom_taxonomies = get_taxonomies( [ '_builtin' => false ] );
// 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' ] );
$custom_terms = (array) get_terms( $custom_taxonomies, [ 'get' => 'all' ] ); // @phpstan-ignore-line
$custom_terms = $this->process_orphaned_terms( $custom_terms );
$custom_terms = self::topologically_sort_terms( $custom_terms );
return $custom_terms;
Expand Down Expand Up @@ -323,7 +323,7 @@ private function bloginfo_rss( $section ) {

private function find_user_from_any_object( $user ) {
if ( is_numeric( $user ) ) {
return get_user_by( 'id', $user );
return get_user_by( 'id', (int) $user );
} elseif ( is_string( $user ) ) {
return get_user_by( 'login', $user );
} elseif ( isset( $user->ID ) ) {
Expand All @@ -334,10 +334,10 @@ private function find_user_from_any_object( $user ) {

private function find_category_from_any_object( $category ) {
if ( is_numeric( $category ) ) {
return get_term( $category, 'category' );
return get_term( (int) $category, 'category' );
} elseif ( is_string( $category ) ) {
$term = term_exists( $category, 'category' );
return isset( $term['term_id'] ) ? get_term( $term['term_id'], 'category' ) : false;
return isset( $term['term_id'] ) ? get_term( (int) $term['term_id'], 'category' ) : false;
} elseif ( isset( $category->term_id ) ) {
return get_term( $category->term_id, 'category' );
}
Expand Down
40 changes: 20 additions & 20 deletions src/WP_Export_WXR_Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function header() {

COMMENT;
return $oxymel
->xml
->xml // @phpstan-ignore-line
->comment( $comment )
->raw( $wp_generator_tag )
->open_rss(
Expand All @@ -105,7 +105,7 @@ public function header() {
public function site_metadata() {
$oxymel = new Oxymel();
$metadata = $this->export->site_metadata();
return $oxymel
return $oxymel // @phpstan-ignore-line
->title( $metadata['name'] )
->link( $metadata['url'] )
->description( $metadata['description'] )
Expand All @@ -129,7 +129,7 @@ public function authors() {
->tag( 'wp:author_display_name' )->contains->cdata( $author->display_name )->end
->tag( 'wp:author_first_name' )->contains->cdata( $author->user_firstname )->end
->tag( 'wp:author_last_name' )->contains->cdata( $author->user_lastname )->end
->end;
->end; // @phpstan-ignore-line
}
return $oxymel->to_string();
}
Expand All @@ -145,7 +145,7 @@ public function categories() {
->tag( 'wp:category_parent', $category->parent_slug )
->optional_cdata( 'wp:cat_name', $category->name )
->optional_cdata( 'wp:category_description', $category->description )
->end;
->end; // @phpstan-ignore-line
}
return $oxymel->to_string();
}
Expand All @@ -159,7 +159,7 @@ public function tags() {
->tag( 'wp:tag_slug', $tag->slug )
->optional_cdata( 'wp:tag_name', $tag->name )
->optional_cdata( 'wp:tag_description', $tag->description )
->end;
->end; // @phpstan-ignore-line
}
return $oxymel->to_string();
}
Expand All @@ -186,10 +186,10 @@ public function post( $post ) {
$GLOBALS['post'] = $post;
setup_postdata( $post );

$oxymel->item->contains
$oxymel->item->contains // @phpstan-ignore-line
->tag( 'title' )->contains->cdata( apply_filters( 'the_title_export', $post->post_title ) )->end // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress native hook.
->link( esc_url( apply_filters( 'the_permalink_rss', get_permalink() ) ) ) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress native hook.
->pubDate( mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ) )
->pubDate( mysql2date( 'D, d M Y H:i:s +0000', (string) get_post_time( 'Y-m-d H:i:s', true ), false ) )
->tag( 'dc:creator', get_the_author_meta( 'login' ) )
->guid( esc_url( get_the_guid() ), [ 'isPermaLink' => 'false' ] )
->description( '' )
Expand All @@ -211,23 +211,23 @@ public function post( $post ) {
->tag( 'wp:is_sticky', $post->is_sticky )
->optional( 'wp:attachment_url', wp_get_attachment_url( $post->ID ) );
foreach ( $post->terms as $term ) {
$oxymel
$oxymel // @phpstan-ignore-line
->category(
[
'domain' => $term->taxonomy,
'nicename' => $term->slug,
]
)->contains->cdata( $term->name )->end;
)->contains->cdata( $term->name )->end; // @phpstan-ignore-line
}
foreach ( $post->meta as $meta ) {
$oxymel
$oxymel // @phpstan-ignore-line
->tag( 'wp:postmeta' )->contains
->tag( 'wp:meta_key', $meta->meta_key )
->tag( 'wp:meta_value' )->contains->cdata( $meta->meta_value )->end
->end;
->end; // @phpstan-ignore-line
}
foreach ( $post->comments as $comment ) {
$oxymel
$oxymel // @phpstan-ignore-line
->tag( 'wp:comment' )->contains
->tag( 'wp:comment_id', $comment->comment_ID )
->tag( 'wp:comment_author' )->contains->cdata( $comment->comment_author )->end
Expand All @@ -242,16 +242,16 @@ public function post( $post ) {
->tag( 'wp:comment_parent', $comment->comment_parent )
->tag( 'wp:comment_user_id', $comment->user_id )
->oxymel( $this->comment_meta( $comment ) )
->end;
->end; // @phpstan-ignore-line
}
$oxymel
->end;
$oxymel // @phpstan-ignore-line
->end; // @phpstan-ignore-line
return $oxymel->to_string();
}

public function footer() {
$oxymel = new Oxymel();
return $oxymel->close_channel->close_rss->to_string();
return $oxymel->close_channel->close_rss->to_string(); // @phpstan-ignore-line
}

protected function terms( $terms ) {
Expand All @@ -266,10 +266,10 @@ protected function terms( $terms ) {
$oxymel
->tag( 'wp:term_parent', $term->parent_slug );
}
$oxymel
$oxymel // @phpstan-ignore-line
->optional_cdata( 'wp:term_name', $term->name )
->optional_cdata( 'wp:term_description', $term->description )
->end;
->end; // @phpstan-ignore-line
}
return $oxymel->to_string();
}
Expand All @@ -282,10 +282,10 @@ protected function comment_meta( $comment ) {
}
$oxymel = new WP_Export_Oxymel();
foreach ( $metas as $meta ) {
$oxymel->tag( 'wp:commentmeta' )->contains
$oxymel->tag( 'wp:commentmeta' )->contains // @phpstan-ignore-line
->tag( 'wp:meta_key', $meta->meta_key )
->tag( 'wp:meta_value' )->contains->cdata( $meta->meta_value )->end
->end;
->end; // @phpstan-ignore-line
}
return $oxymel;
}
Expand Down
3 changes: 3 additions & 0 deletions src/WP_Map_Iterator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @extends IteratorIterator<mixed, mixed, \Iterator<mixed>>
*/
class WP_Map_Iterator extends IteratorIterator {
/**
* @var callable
Expand Down
3 changes: 2 additions & 1 deletion src/WP_Post_IDs_Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public function valid() {
private function load_next_posts_from_db() {
$next_batch_post_ids = array_splice( $this->ids_left, 0, $this->limit );
$in_post_ids_sql = _wp_export_build_IN_condition( 'ID', $next_batch_post_ids );
$this->results = $this->db->get_results( "SELECT * FROM {$this->db->posts} WHERE {$in_post_ids_sql}" );
$results = $this->db->get_results( "SELECT * FROM {$this->db->posts} WHERE {$in_post_ids_sql}" );
$this->results = is_array( $results ) ? $results : array();
if ( ! $this->results ) {
if ( $this->db->last_error ) {
throw new WP_Iterator_Exception( "Database error: {$this->db->last_error}" );
Expand Down