Skip to content

Commit 3e8fed7

Browse files
committed
Use function stub to override filtered return value typing
1 parent 351885e commit 3e8fed7

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Functions with filtered return values that extend what core returns.
4+
*
5+
* @package performance-lab
6+
*/
7+
8+
/**
9+
* Retrieves attachment metadata for attachment ID.
10+
*
11+
* This is a wrapper for {@see wp_get_attachment_metadata()} to add the typing which is augmented by the
12+
* `wp_generate_attachment_metadata` via {@see dominant_color_metadata()} and {@see webp_uploads_create_sources_property()}.
13+
*
14+
* @since 2.1.0
15+
* @since 6.0.0 The `$filesize` value was added to the returned array.
16+
*
17+
* @param int $attachment_id Attachment post ID. Defaults to global $post.
18+
* @param bool $unfiltered Optional. If true, filters are not run. Default false.
19+
*
20+
* @return array{
21+
* width: int,
22+
* height: int,
23+
* file: string,
24+
* sizes: array<string, array{ file: string, width: int, height: int, 'mime-type': string, sources?: array<string, array{ file: string, filesize: int }> }>,
25+
* image_meta: array<string, mixed>,
26+
* filesize: int,
27+
* sources?: array<string, array{ file: string, filesize: int }>,
28+
* has_transparency?: bool,
29+
* dominant_color?: string
30+
* }|null Attachment metadata. Null on failure.
31+
*/
32+
function wp_get_attachment_metadata( int $attachment_id = 0, bool $unfiltered = false ): ?array {}

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ parameters:
1818
# See <https://github.com/php-stubs/wordpress-stubs/issues/100>.
1919
- vendor/phpstan/php-8-stubs/stubs/ext/standard/str_contains.php
2020
- vendor/phpstan/php-8-stubs/stubs/ext/standard/str_starts_with.php
21+
stubFiles:
22+
- bin/phpstan/filtered-functions.stub
2123
dynamicConstantNames:
2224
- PERFLAB_OBJECT_CACHE_DROPIN_VERSION

plugins/webp-uploads/hooks.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -553,27 +553,7 @@ function webp_uploads_update_image_references( $content ) {
553553
* @return string The updated img tag.
554554
*/
555555
function webp_uploads_img_tag_update_mime_type( $original_image, $context, $attachment_id ) {
556-
$image = $original_image;
557-
558-
/**
559-
* Metadata potentially amended by webp_uploads_create_sources_property().
560-
*
561-
* Note the sources key is not normally present in the response for wp_get_attachment_metadata(). The sources
562-
* key here, however, is being injected via the 'wp_generate_attachment_metadata' filter via the
563-
* webp_uploads_create_sources_property() function.
564-
*
565-
* @see webp_uploads_create_sources_property()
566-
*
567-
* @var array{
568-
* width: int,
569-
* height: int,
570-
* file: non-falsy-string,
571-
* sizes: array,
572-
* image_meta: array,
573-
* filesize: int,
574-
* sources?: array<string, array{ file: string, filesize: int }>
575-
* } $metadata
576-
*/
556+
$image = $original_image;
577557
$metadata = wp_get_attachment_metadata( $attachment_id );
578558

579559
if ( empty( $metadata['file'] ) ) {

0 commit comments

Comments
 (0)