Skip to content

Commit 338552c

Browse files
Copilotswissspidy
andcommitted
Fix PHPStan level 9 errors
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 4fa5ca6 commit 338552c

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

src/Export_Command.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function __invoke( $_, $assoc_args ) {
181181
'wp_export_new_file',
182182
static function ( $file_path ) {
183183
WP_CLI::log( sprintf( 'Writing to file %s', $file_path ) );
184-
Utils\wp_clear_object_cache();
184+
Utils\wp_clear_object_cache(); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.wp_clear_object_cacheDeprecatedRemoved
185185
}
186186
);
187187

@@ -190,15 +190,15 @@ static function ( $file_path ) {
190190
wp_export(
191191
[
192192
'filters' => $this->export_args,
193-
'writer' => 'WP_Export_File_Writer',
193+
'writer' => WP_Export_File_Writer::class,
194194
'writer_args' => 'php://output',
195195
]
196196
);
197197
} else {
198198
wp_export(
199199
[
200200
'filters' => $this->export_args,
201-
'writer' => 'WP_Export_Split_Files_Writer',
201+
'writer' => WP_Export_Split_Files_Writer::class,
202202
'writer_args' => [
203203
'max_file_size' => $this->max_file_size,
204204
'destination_directory' => $this->wxr_path,
@@ -234,6 +234,7 @@ private function validate_args( $args ) {
234234

235235
foreach ( $args as $key => $value ) {
236236
if ( is_callable( [ $this, 'check_' . $key ] ) ) {
237+
/** @phpstan-ignore argument.type */
237238
$result = call_user_func( [ $this, 'check_' . $key ], $value );
238239
if ( false === $result ) {
239240
$has_errors = true;
@@ -281,11 +282,11 @@ private function check_start_date( $date ) {
281282
}
282283

283284
$time = strtotime( $date );
284-
if ( ! empty( $date ) && ! $time ) {
285+
if ( ! empty( $date ) && false === $time ) {
285286
WP_CLI::warning( sprintf( 'The start_date %s is invalid.', $date ) );
286287
return false;
287288
}
288-
$this->export_args['start_date'] = date( 'Y-m-d', $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
289+
$this->export_args['start_date'] = date( 'Y-m-d', (int) $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
289290
return true;
290291
}
291292

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

302303
$time = strtotime( $date );
303-
if ( ! empty( $date ) && ! $time ) {
304+
if ( ! empty( $date ) && false === $time ) {
304305
WP_CLI::warning( sprintf( 'The end_date %s is invalid.', $date ) );
305306
return false;
306307
}
307-
$this->export_args['end_date'] = date( 'Y-m-d', $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
308+
$this->export_args['end_date'] = date( 'Y-m-d', (int) $time ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
308309
return true;
309310
}
310311

@@ -420,8 +421,8 @@ private function check_author( $author ) {
420421
}
421422

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

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

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

494498
$stati = get_post_stati();
495-
if ( empty( $stati ) || is_wp_error( $stati ) ) {
499+
if ( empty( $stati ) ) {
496500
WP_CLI::warning( 'Could not find any post stati.' );
497501
return false;
498502
}

src/WP_Export_Oxymel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function optional( $tag_name, $contents ) {
1010

1111
public function optional_cdata( $tag_name, $contents ) {
1212
if ( $contents ) {
13-
$this->$tag_name->contains->cdata( $contents )->end;
13+
$this->$tag_name->contains->cdata( $contents )->end; // phpstan-ignore-line
1414
}
1515
return $this;
1616
}

src/WP_Export_Query.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function custom_taxonomies_terms() {
122122
}
123123
$custom_taxonomies = get_taxonomies( [ '_builtin' => false ] );
124124
// phpcs:ignore WordPress.WP.DeprecatedParameters.Get_termsParam2Found -- Deprecated, but we need to support older versions of WordPress.
125-
$custom_terms = (array) get_terms( $custom_taxonomies, [ 'get' => 'all' ] );
125+
$custom_terms = (array) get_terms( $custom_taxonomies, [ 'get' => 'all' ] ); // phpstan-ignore-line
126126
$custom_terms = $this->process_orphaned_terms( $custom_terms );
127127
$custom_terms = self::topologically_sort_terms( $custom_terms );
128128
return $custom_terms;
@@ -323,7 +323,7 @@ private function bloginfo_rss( $section ) {
323323

324324
private function find_user_from_any_object( $user ) {
325325
if ( is_numeric( $user ) ) {
326-
return get_user_by( 'id', $user );
326+
return get_user_by( 'id', (int) $user );
327327
} elseif ( is_string( $user ) ) {
328328
return get_user_by( 'login', $user );
329329
} elseif ( isset( $user->ID ) ) {

src/WP_Export_WXR_Formatter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function post( $post ) {
224224
->tag( 'wp:postmeta' )->contains
225225
->tag( 'wp:meta_key', $meta->meta_key )
226226
->tag( 'wp:meta_value' )->contains->cdata( $meta->meta_value )->end
227-
->end;
227+
->end; // phpstan-ignore-line
228228
}
229229
foreach ( $post->comments as $comment ) {
230230
$oxymel
@@ -242,16 +242,16 @@ public function post( $post ) {
242242
->tag( 'wp:comment_parent', $comment->comment_parent )
243243
->tag( 'wp:comment_user_id', $comment->user_id )
244244
->oxymel( $this->comment_meta( $comment ) )
245-
->end;
245+
->end; // phpstan-ignore-line
246246
}
247247
$oxymel
248-
->end;
248+
->end; // phpstan-ignore-line
249249
return $oxymel->to_string();
250250
}
251251

252252
public function footer() {
253253
$oxymel = new Oxymel();
254-
return $oxymel->close_channel->close_rss->to_string();
254+
return $oxymel->close_channel->close_rss->to_string(); // phpstan-ignore-line
255255
}
256256

257257
protected function terms( $terms ) {
@@ -269,7 +269,7 @@ protected function terms( $terms ) {
269269
$oxymel
270270
->optional_cdata( 'wp:term_name', $term->name )
271271
->optional_cdata( 'wp:term_description', $term->description )
272-
->end;
272+
->end; // phpstan-ignore-line
273273
}
274274
return $oxymel->to_string();
275275
}
@@ -285,7 +285,7 @@ protected function comment_meta( $comment ) {
285285
$oxymel->tag( 'wp:commentmeta' )->contains
286286
->tag( 'wp:meta_key', $meta->meta_key )
287287
->tag( 'wp:meta_value' )->contains->cdata( $meta->meta_value )->end
288-
->end;
288+
->end; // phpstan-ignore-line
289289
}
290290
return $oxymel;
291291
}

src/WP_Map_Iterator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
/**
4+
* @extends IteratorIterator<mixed, mixed, \Iterator<mixed>>
5+
*/
36
class WP_Map_Iterator extends IteratorIterator {
47
/**
58
* @var callable

src/WP_Post_IDs_Iterator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public function valid() {
9191
private function load_next_posts_from_db() {
9292
$next_batch_post_ids = array_splice( $this->ids_left, 0, $this->limit );
9393
$in_post_ids_sql = _wp_export_build_IN_condition( 'ID', $next_batch_post_ids );
94-
$this->results = $this->db->get_results( "SELECT * FROM {$this->db->posts} WHERE {$in_post_ids_sql}" );
94+
$results = $this->db->get_results( "SELECT * FROM {$this->db->posts} WHERE {$in_post_ids_sql}" );
95+
$this->results = is_array( $results ) ? $results : array();
9596
if ( ! $this->results ) {
9697
if ( $this->db->last_error ) {
9798
throw new WP_Iterator_Exception( "Database error: {$this->db->last_error}" );

0 commit comments

Comments
 (0)