Skip to content

Commit 8465514

Browse files
authored
Merge pull request #1003 from Codeinwp/fix/param-types
fix: type verification for filter values
2 parents c8793ca + 49dffaf commit 8465514

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

inc/admin.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,14 @@ public function inline_bootstrap_script() {
575575
/**
576576
* Add settings links in the plugin listing page.
577577
*
578-
* @param string[] $links Old plugin links.
578+
* @param string[]|mixed $links Old plugin links.
579579
*
580-
* @return string[] Altered links.
580+
* @return string[]|mixed Altered links.
581581
*/
582582
public function add_action_links( $links ) {
583+
if ( ! is_array( $links ) ) {
584+
return $links;
585+
}
583586
return array_merge(
584587
$links,
585588
[

inc/app_replacer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,10 @@ public function url_has_dam_flag( $url ) {
654654
/**
655655
* Get the optimized image url for the image url.
656656
*
657-
* @param string $url The image URL.
658-
* @param mixed $width The image width.
659-
* @param mixed $height The image height.
660-
* @param array $resize The resize properties.
657+
* @param string $url The image URL.
658+
* @param mixed $width The image width.
659+
* @param mixed $height The image height.
660+
* @param array<string, mixed>|mixed $resize The resize properties.
661661
*
662662
* @return string
663663
*/
@@ -668,7 +668,7 @@ protected function get_optimized_image_url( $url, $width, $height, $resize = []
668668
->width( $width )
669669
->height( $height );
670670

671-
if ( ! empty( $resize['type'] ) ) {
671+
if ( is_array( $resize ) && ! empty( $resize['type'] ) ) {
672672
$optimized_image->resize( $resize['type'], $resize['gravity'] ?? Position::CENTER, $resize['enlarge'] ?? false );
673673

674674
}

inc/tag_replacer.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,15 +809,18 @@ public function change_url_for_size( $original_url, $width, $height, $dpr = 1 )
809809
/**
810810
* Replace image URLs in the srcset attributes and in case there is a resize in action, also replace the sizes.
811811
*
812-
* @param array<int, array{url: string, descriptor: string, value: int}> $sources Array of image sources.
813-
* @param array{0: int, 1: int}|int[] $size_array Array of width and height values in pixels (in that order).
814-
* @param string $image_src The 'src' of the image.
815-
* @param array<string, mixed> $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
816-
* @param int $attachment_id Image attachment ID or 0.
812+
* @param array<int, array{url: string, descriptor: string, value: int}>|mixed $sources Array of image sources.
813+
* @param array{0: int, 1: int}|int[] $size_array Array of width and height values in pixels (in that order).
814+
* @param string $image_src The 'src' of the image.
815+
* @param array<string, mixed> $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
816+
* @param int $attachment_id Image attachment ID or 0.
817817
*
818-
* @return array
818+
* @return array|mixed
819819
*/
820820
public function filter_srcset_attr( $sources = [], $size_array = [], $image_src = '', $image_meta = [], $attachment_id = 0 ) {
821+
if ( ! is_array( $sources ) ) {
822+
return $sources;
823+
}
821824
if ( Optml_Media_Offload::is_uploaded_image( $image_src ) ) {
822825
return $sources;
823826
}

phpstan-baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,6 @@ parameters:
516516
count: 1
517517
path: inc/app_replacer.php
518518

519-
-
520-
message: '#^Method Optml_App_Replacer\:\:get_optimized_image_url\(\) has parameter \$resize with no value type specified in iterable type array\.$#'
521-
identifier: missingType.iterableValue
522-
count: 1
523-
path: inc/app_replacer.php
524-
525519
-
526520
message: '#^Method Optml_App_Replacer\:\:get_upload_resource\(\) return type has no value type specified in iterable type array\.$#'
527521
identifier: missingType.iterableValue
@@ -2790,12 +2784,6 @@ parameters:
27902784
count: 1
27912785
path: inc/tag_replacer.php
27922786

2793-
-
2794-
message: '#^Method Optml_Tag_Replacer\:\:filter_srcset_attr\(\) return type has no value type specified in iterable type array\.$#'
2795-
identifier: missingType.iterableValue
2796-
count: 1
2797-
path: inc/tag_replacer.php
2798-
27992787
-
28002788
message: '#^Method Optml_Tag_Replacer\:\:init\(\) has no return type specified\.$#'
28012789
identifier: missingType.return

0 commit comments

Comments
 (0)