Skip to content

Commit 658bcc5

Browse files
committed
Docs: Move the oembed_min_max_width shape to its docblock.
In r62719 an inline `@var` was added after the `apply_filters()` call in `get_oembed_response_data()`, narrowing the filtered widths for `clamp()`. A type declared below the assignment it describes is confusing to read, but it could not go above, since the filter's docblock must immediately precede `apply_filters()` or the hook is reported as undocumented. The shape is now declared once, as a `@phpstan-param` in the filter docblock next to the `@param` hash it refines. The `min` and `max` keys are also marked `Required.` in the hash. Since r65217 that marker makes a key required, where the keys of a `@param` hash are otherwise read as optional because a caller may pass a subset of them. That does not fit a filtered value: core always passes both keys, and a callback must return both, since they are read unconditionally. The documented defaults therefore describe the values core supplies, not a fallback for an omitted key. The `@phpstan-param` is kept regardless, because the hash only says `int`, while the shape narrows the widths to `positive-int`. Developed in WordPress#15264. Follow-up to r62719, r65217. Props westonruter, dmsnell. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@65247 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 16a1d52 commit 658bcc5

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/wp-includes/embed.php‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,11 @@ function get_oembed_response_data( $post, $width ) {
582582
* @param array $min_max_width {
583583
* Minimum and maximum widths for the oEmbed response.
584584
*
585-
* @type int $min Minimum width. Default 200.
586-
* @type int $max Maximum width. Default 600.
585+
* @type int $min Minimum width. Default 200. Required.
586+
* @type int $max Maximum width. Default 600. Required.
587587
* }
588+
*
589+
* @phpstan-param array{ min: positive-int, max: positive-int } $min_max_width
588590
*/
589591
$min_max_width = apply_filters(
590592
'oembed_min_max_width',
@@ -594,7 +596,6 @@ function get_oembed_response_data( $post, $width ) {
594596
)
595597
);
596598

597-
/** @var array{ min: positive-int, max: positive-int } $min_max_width */
598599
$width = clamp( $width, $min_max_width['min'], $min_max_width['max'] );
599600
$height = max( (int) ceil( $width / 16 * 9 ), 200 );
600601

0 commit comments

Comments
 (0)