Skip to content

Commit 8ef2bf4

Browse files
authored
Fix PHPStan errors with WordPress 7.1 stubs (#257)
1 parent 9708085 commit 8ef2bf4

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎src/Media_Command.php‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ public function regenerate( $args, $assoc_args = array() ) {
198198
}
199199

200200
$images = $this->get_images( $args, $additional_mime_types );
201+
$posts = $images->posts;
201202
$count = $images->post_count;
202203

203-
if ( ! $count ) {
204+
if ( ! $count || ! is_array( $posts ) ) {
204205
WP_CLI::warning( 'No images found.' );
205206
return;
206207
}
@@ -225,7 +226,7 @@ public function regenerate( $args, $assoc_args = array() ) {
225226
/**
226227
* @var int $post_id
227228
*/
228-
foreach ( $images->posts as $post_id ) {
229+
foreach ( $posts as $post_id ) {
229230
++$number;
230231
if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
231232
// @phpstan-ignore function.deprecated
@@ -338,9 +339,10 @@ public function prune( $args, $assoc_args = array() ) {
338339
}
339340

340341
$images = $this->get_images( $args, $additional_mime_types );
342+
$posts = $images->posts;
341343
$count = $images->post_count;
342344

343-
if ( ! $count ) {
345+
if ( ! $count || ! is_array( $posts ) ) {
344346
WP_CLI::warning( 'No images found.' );
345347
return;
346348
}
@@ -361,7 +363,7 @@ public function prune( $args, $assoc_args = array() ) {
361363
/**
362364
* @var int $post_id
363365
*/
364-
foreach ( $images->posts as $post_id ) {
366+
foreach ( $posts as $post_id ) {
365367
++$number;
366368
if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
367369
// @phpstan-ignore function.deprecated
@@ -1861,7 +1863,7 @@ private function filter_upload_dir( $uploads ) {
18611863
* @param int $id
18621864
* @param array $new_metadata
18631865
* @param string[] $image_sizes
1864-
* @param array{sizes: array<string, mixed>}|false $metadata
1866+
* @param array{sizes?: array<string, mixed>}|false $metadata
18651867
* @return string[] The sizes that were actually regenerated.
18661868
*/
18671869
private function update_attachment_metadata_for_image_size( $id, $new_metadata, $image_sizes, $metadata ) {
@@ -2054,10 +2056,11 @@ public function fix_orientation( $args, $assoc_args ) {
20542056
}
20552057

20562058
$images = $this->get_images( $args );
2059+
$posts = $images->posts;
20572060
$count = $images->post_count;
20582061
$dry_run = Utils\get_flag_value( $assoc_args, 'dry-run' );
20592062

2060-
if ( ! $count ) {
2063+
if ( ! $count || ! is_array( $posts ) ) {
20612064
WP_CLI::error( 'No images found.' );
20622065
}
20632066

@@ -2068,7 +2071,7 @@ public function fix_orientation( $args, $assoc_args ) {
20682071
/**
20692072
* @var int $post_id
20702073
*/
2071-
foreach ( $images->posts as $post_id ) {
2074+
foreach ( $posts as $post_id ) {
20722075
++$number;
20732076
if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
20742077
// @phpstan-ignore function.deprecated

0 commit comments

Comments
 (0)