Skip to content

Commit a606223

Browse files
fix: update parameter type hinting and return type for calculate_image_srcset method
1 parent 759c4bc commit a606223

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

inc/media_offload.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,20 @@ public static function get_image_size_from_width( $sizes, $width, $filename, $ju
376376
/**
377377
* Replace image URLs in the srcset attributes.
378378
*
379-
* @param array<int, array{url: string, descriptor: string, value: int}> $sources Array of image sources.
379+
* @param mixed|array<int, array{url: string, descriptor: string, value: int}> $sources Array of image sources.
380380
* @param array{0: int, 1: int} $size_array Array of width and height values in pixels (in that order).
381381
* @param string $image_src The 'src' of the image.
382382
* @param array<string, mixed> $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
383383
* @param int $attachment_id Image attachment ID or 0.
384384
*
385-
* @return array
385+
* @return array<int, array{url: string, descriptor: string, value: int}>|mixed
386386
*/
387387
public function calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
388388

389+
if ( ! is_array( $sources ) ) {
390+
return $sources;
391+
}
392+
389393
if ( $this->is_legacy_offloaded_attachment( $attachment_id ) ) {
390394
if ( ! Optml_Media_Offload::is_uploaded_image( $image_src ) || ! isset( $image_meta['file'] ) || ! Optml_Media_Offload::is_uploaded_image( $image_meta['file'] ) ) {
391395
return $sources;

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,12 +2088,6 @@ parameters:
20882088
count: 1
20892089
path: inc/media_offload.php
20902090

2091-
-
2092-
message: '#^Method Optml_Media_Offload\:\:calculate_image_srcset\(\) return type has no value type specified in iterable type array\.$#'
2093-
identifier: missingType.iterableValue
2094-
count: 1
2095-
path: inc/media_offload.php
2096-
20972091
-
20982092
message: '#^Method Optml_Media_Offload\:\:clear_offload_errors_meta\(\) has no return type specified\.$#'
20992093
identifier: missingType.return

0 commit comments

Comments
 (0)