Skip to content

Commit 2ab152b

Browse files
committed
refactor: remove redundant missing type entries from phpstan baseline and update type hints in media offload and dam offload utils
1 parent 1f00f57 commit 2ab152b

3 files changed

Lines changed: 13 additions & 134 deletions

File tree

inc/media_offload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,7 @@ public function filter_saved_data( $post_data, $postarr, $unsanitized_postarr, $
24702470
$height = $size[1];
24712471
} else {
24722472
// In case of an image size, we need to calculate the new dimensions for the proper file path.
2473-
$constrained = wp_constrain_dimensions( $metadata['width'], $metadata['height'], $size[0], $size[1] );
2473+
$constrained = wp_constrain_dimensions( $metadata['width'], $metadata['height'], (int) $size[0], (int) $size[1] );
24742474

24752475
$width = $constrained[0];
24762476
$height = $constrained[1];

inc/traits/dam_offload_utils.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function is_new_offloaded_attachment( $id ) {
4949
/**
5050
* Get all registered image sizes.
5151
*
52-
* @return array
52+
* @return array<string, array{width: int, height: int, crop: bool|array<int, string>}>
5353
*/
5454
private function get_all_image_sizes() {
5555
$additional_sizes = wp_get_additional_image_sizes();
@@ -87,7 +87,7 @@ private function get_all_image_sizes() {
8787
*
8888
* @param string $url The image url.
8989
*
90-
* @return array Contains the width and height values in this order.
90+
* @return array{0: string|false, 1: string|false} Contains the width and height values in this order.
9191
*/
9292
private function parse_dimension_from_optimized_url( $url ) {
9393
$catch = [];
@@ -153,10 +153,10 @@ private function is_attachment_edit_page( $attachment_id ) {
153153
/**
154154
* Used to filter the image metadata. Adds optimized image url for all image sizes.
155155
*
156-
* @param array $metadata The attachment metadata.
156+
* @param array<string, mixed> $metadata The attachment metadata.
157157
* @param int $id The attachment id.
158158
*
159-
* @return mixed
159+
* @return array<string, mixed>
160160
*/
161161
private function get_altered_metadata_for_remote_images( $metadata, $id ) {
162162

phpstan-baseline.neon

Lines changed: 8 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,6 @@ parameters:
515515
identifier: missingType.iterableValue
516516
count: 1
517517
path: inc/app_replacer.php
518-
519-
-
520-
message: '#^Method Optml_App_Replacer\:\:get_all_image_sizes\(\) return type has no value type specified in iterable type array\.$#'
521-
identifier: missingType.iterableValue
522-
count: 1
523-
path: inc/app_replacer.php
524-
525-
-
526-
message: '#^Method Optml_App_Replacer\:\:get_altered_metadata_for_remote_images\(\) has parameter \$metadata with no value type specified in iterable type array\.$#'
527-
identifier: missingType.iterableValue
528-
count: 1
529-
path: inc/app_replacer.php
530-
531518
-
532519
message: '#^Method Optml_App_Replacer\:\:get_media_optimized_url\(\) has parameter \$resize with no value type specified in iterable type array\.$#'
533520
identifier: missingType.iterableValue
@@ -557,13 +544,6 @@ parameters:
557544
identifier: missingType.return
558545
count: 1
559546
path: inc/app_replacer.php
560-
561-
-
562-
message: '#^Method Optml_App_Replacer\:\:parse_dimension_from_optimized_url\(\) return type has no value type specified in iterable type array\.$#'
563-
identifier: missingType.iterableValue
564-
count: 1
565-
path: inc/app_replacer.php
566-
567547
-
568548
message: '#^Method Optml_App_Replacer\:\:parse_dimensions_from_filename\(\) return type has no value type specified in iterable type array\.$#'
569549
identifier: missingType.iterableValue
@@ -1541,19 +1521,6 @@ parameters:
15411521
identifier: missingType.iterableValue
15421522
count: 1
15431523
path: inc/dam.php
1544-
1545-
-
1546-
message: '#^Method Optml_Dam\:\:get_all_image_sizes\(\) return type has no value type specified in iterable type array\.$#'
1547-
identifier: missingType.iterableValue
1548-
count: 1
1549-
path: inc/dam.php
1550-
1551-
-
1552-
message: '#^Method Optml_Dam\:\:get_altered_metadata_for_remote_images\(\) has parameter \$metadata with no value type specified in iterable type array\.$#'
1553-
identifier: missingType.iterableValue
1554-
count: 1
1555-
path: inc/dam.php
1556-
15571524
-
15581525
message: '#^Method Optml_Dam\:\:get_dam_imported_attachments\(\) has parameter \$images with no value type specified in iterable type array\.$#'
15591526
identifier: missingType.iterableValue
@@ -1601,13 +1568,6 @@ parameters:
16011568
identifier: missingType.iterableValue
16021569
count: 1
16031570
path: inc/dam.php
1604-
1605-
-
1606-
message: '#^Method Optml_Dam\:\:parse_dimension_from_optimized_url\(\) return type has no value type specified in iterable type array\.$#'
1607-
identifier: missingType.iterableValue
1608-
count: 1
1609-
path: inc/dam.php
1610-
16111571
-
16121572
message: '#^Method Optml_Dam\:\:replace_dam_url_args\(\) has parameter \$args with no value type specified in iterable type array\.$#'
16131573
identifier: missingType.iterableValue
@@ -1773,43 +1733,43 @@ parameters:
17731733
-
17741734
message: '#^Method Optml_Lazyload_Replacer\:\:size_to_dimension\(\) has parameter \$image_meta with no value type specified in iterable type array\.$#'
17751735
identifier: missingType.iterableValue
1776-
count: 1
1736+
count: 2
17771737
path: inc/lazyload_replacer.php
17781738

17791739
-
17801740
message: '#^Method Optml_Lazyload_Replacer\:\:size_to_dimension\(\) return type has no value type specified in iterable type array\.$#'
17811741
identifier: missingType.iterableValue
1782-
count: 1
1742+
count: 2
17831743
path: inc/lazyload_replacer.php
17841744

17851745
-
17861746
message: '#^Method Optml_Lazyload_Replacer\:\:to_map_values\(\) has parameter \$map with no value type specified in iterable type array\.$#'
17871747
identifier: missingType.iterableValue
1788-
count: 1
1748+
count: 2
17891749
path: inc/lazyload_replacer.php
17901750

17911751
-
17921752
message: '#^Method Optml_Lazyload_Replacer\:\:to_optml_crop\(\) has parameter \$crop_args with no value type specified in iterable type array\.$#'
17931753
identifier: missingType.iterableValue
1794-
count: 1
1754+
count: 2
17951755
path: inc/lazyload_replacer.php
17961756

17971757
-
17981758
message: '#^Method Optml_Lazyload_Replacer\:\:to_optml_crop\(\) return type has no value type specified in iterable type array\.$#'
17991759
identifier: missingType.iterableValue
1800-
count: 1
1760+
count: 2
18011761
path: inc/lazyload_replacer.php
18021762

18031763
-
18041764
message: '#^Method Optml_Lazyload_Replacer\:\:to_optml_watermark\(\) has parameter \$watermark_args with no value type specified in iterable type array\.$#'
18051765
identifier: missingType.iterableValue
1806-
count: 1
1766+
count: 2
18071767
path: inc/lazyload_replacer.php
18081768

18091769
-
18101770
message: '#^Method Optml_Lazyload_Replacer\:\:to_optml_watermark\(\) return type has no value type specified in iterable type array\.$#'
18111771
identifier: missingType.iterableValue
1812-
count: 1
1772+
count: 2
18131773
path: inc/lazyload_replacer.php
18141774

18151775
-
@@ -1821,7 +1781,7 @@ parameters:
18211781
-
18221782
message: '#^Property Optml_Lazyload_Replacer\:\:\$dimension_cache type has no value type specified in iterable type array\.$#'
18231783
identifier: missingType.iterableValue
1824-
count: 1
1784+
count: 2
18251785
path: inc/lazyload_replacer.php
18261786

18271787
-
@@ -2159,19 +2119,6 @@ parameters:
21592119
identifier: missingType.iterableValue
21602120
count: 1
21612121
path: inc/media_offload.php
2162-
2163-
-
2164-
message: '#^Method Optml_Media_Offload\:\:get_all_image_sizes\(\) return type has no value type specified in iterable type array\.$#'
2165-
identifier: missingType.iterableValue
2166-
count: 1
2167-
path: inc/media_offload.php
2168-
2169-
-
2170-
message: '#^Method Optml_Media_Offload\:\:get_altered_metadata_for_remote_images\(\) has parameter \$metadata with no value type specified in iterable type array\.$#'
2171-
identifier: missingType.iterableValue
2172-
count: 1
2173-
path: inc/media_offload.php
2174-
21752122
-
21762123
message: '#^Method Optml_Media_Offload\:\:get_image_id_from_content\(\) return type has no value type specified in iterable type array\.$#'
21772124
identifier: missingType.iterableValue
@@ -2339,13 +2286,6 @@ parameters:
23392286
identifier: missingType.parameter
23402287
count: 1
23412288
path: inc/media_offload.php
2342-
2343-
-
2344-
message: '#^Method Optml_Media_Offload\:\:parse_dimension_from_optimized_url\(\) return type has no value type specified in iterable type array\.$#'
2345-
identifier: missingType.iterableValue
2346-
count: 1
2347-
path: inc/media_offload.php
2348-
23492289
-
23502290
message: '#^Method Optml_Media_Offload\:\:pre_filter_rest_content\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
23512291
identifier: missingType.generics
@@ -2561,13 +2501,6 @@ parameters:
25612501
identifier: missingType.return
25622502
count: 1
25632503
path: inc/media_rename/attachment_edit.php
2564-
2565-
-
2566-
message: '#^Method Optml_Attachment_Model\:\:get_all_image_sizes\(\) return type has no value type specified in iterable type array\.$#'
2567-
identifier: missingType.iterableValue
2568-
count: 1
2569-
path: inc/media_rename/attachment_model.php
2570-
25712504
-
25722505
message: '#^Method Optml_Attachment_Model\:\:get_all_image_sizes_paths\(\) return type has no value type specified in iterable type array\.$#'
25732506
identifier: missingType.iterableValue
@@ -2579,13 +2512,6 @@ parameters:
25792512
identifier: missingType.iterableValue
25802513
count: 1
25812514
path: inc/media_rename/attachment_model.php
2582-
2583-
-
2584-
message: '#^Method Optml_Attachment_Model\:\:get_altered_metadata_for_remote_images\(\) has parameter \$metadata with no value type specified in iterable type array\.$#'
2585-
identifier: missingType.iterableValue
2586-
count: 1
2587-
path: inc/media_rename/attachment_model.php
2588-
25892515
-
25902516
message: '#^Method Optml_Attachment_Model\:\:get_attachment_metadata\(\) return type has no value type specified in iterable type array\.$#'
25912517
identifier: missingType.iterableValue
@@ -2603,13 +2529,6 @@ parameters:
26032529
identifier: missingType.return
26042530
count: 1
26052531
path: inc/media_rename/attachment_model.php
2606-
2607-
-
2608-
message: '#^Method Optml_Attachment_Model\:\:parse_dimension_from_optimized_url\(\) return type has no value type specified in iterable type array\.$#'
2609-
identifier: missingType.iterableValue
2610-
count: 1
2611-
path: inc/media_rename/attachment_model.php
2612-
26132532
-
26142533
message: '#^Method Optml_Attachment_Model\:\:size_to_dimension\(\) has parameter \$image_meta with no value type specified in iterable type array\.$#'
26152534
identifier: missingType.iterableValue
@@ -3041,19 +2960,6 @@ parameters:
30412960
identifier: missingType.iterableValue
30422961
count: 1
30432962
path: inc/tag_replacer.php
3044-
3045-
-
3046-
message: '#^Method Optml_Tag_Replacer\:\:get_all_image_sizes\(\) return type has no value type specified in iterable type array\.$#'
3047-
identifier: missingType.iterableValue
3048-
count: 1
3049-
path: inc/tag_replacer.php
3050-
3051-
-
3052-
message: '#^Method Optml_Tag_Replacer\:\:get_altered_metadata_for_remote_images\(\) has parameter \$metadata with no value type specified in iterable type array\.$#'
3053-
identifier: missingType.iterableValue
3054-
count: 1
3055-
path: inc/tag_replacer.php
3056-
30572963
-
30582964
message: '#^Method Optml_Tag_Replacer\:\:init\(\) has no return type specified\.$#'
30592965
identifier: missingType.return
@@ -3065,13 +2971,6 @@ parameters:
30652971
identifier: missingType.parameter
30662972
count: 1
30672973
path: inc/tag_replacer.php
3068-
3069-
-
3070-
message: '#^Method Optml_Tag_Replacer\:\:parse_dimension_from_optimized_url\(\) return type has no value type specified in iterable type array\.$#'
3071-
identifier: missingType.iterableValue
3072-
count: 1
3073-
path: inc/tag_replacer.php
3074-
30752974
-
30762975
message: '#^Method Optml_Tag_Replacer\:\:parse_dimensions_from_tag\(\) has parameter \$args with no value type specified in iterable type array\.$#'
30772976
identifier: missingType.iterableValue
@@ -3173,19 +3072,6 @@ parameters:
31733072
identifier: missingType.iterableValue
31743073
count: 1
31753074
path: inc/url_replacer.php
3176-
3177-
-
3178-
message: '#^Method Optml_Url_Replacer\:\:get_all_image_sizes\(\) return type has no value type specified in iterable type array\.$#'
3179-
identifier: missingType.iterableValue
3180-
count: 1
3181-
path: inc/url_replacer.php
3182-
3183-
-
3184-
message: '#^Method Optml_Url_Replacer\:\:get_altered_metadata_for_remote_images\(\) has parameter \$metadata with no value type specified in iterable type array\.$#'
3185-
identifier: missingType.iterableValue
3186-
count: 1
3187-
path: inc/url_replacer.php
3188-
31893075
-
31903076
message: '#^Method Optml_Url_Replacer\:\:init\(\) has no return type specified\.$#'
31913077
identifier: missingType.return
@@ -3215,13 +3101,6 @@ parameters:
32153101
identifier: missingType.parameter
32163102
count: 1
32173103
path: inc/url_replacer.php
3218-
3219-
-
3220-
message: '#^Method Optml_Url_Replacer\:\:parse_dimension_from_optimized_url\(\) return type has no value type specified in iterable type array\.$#'
3221-
identifier: missingType.iterableValue
3222-
count: 1
3223-
path: inc/url_replacer.php
3224-
32253104
-
32263105
message: '#^Method Optml_Url_Replacer\:\:size_to_dimension\(\) has parameter \$image_meta with no value type specified in iterable type array\.$#'
32273106
identifier: missingType.iterableValue

0 commit comments

Comments
 (0)