Skip to content

docs: fix return type on gutenberg_get_typography_value_and_unit() - #68392

Merged
westonruter merged 4 commits into
WordPress:trunkfrom
justlevine:docs/fix-return-type-gutenberg_get_typography_value_and_unit()
Oct 25, 2026
Merged

westonruter merged 4 commits into
WordPress:trunkfrom
justlevine:docs/fix-return-type-gutenberg_get_typography_value_and_unit()

Conversation

@justlevine

Copy link
Copy Markdown
Contributor

What?

This PR fixes the PHPDoc return type for gutenberg_get_typography_value_and_unit() to correctly indicate it may return null.

Why?

While this issue was surfaced by PHPStan (via #66693) it can be remediated independently as part of #66598

How?

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@Mamaduka Mamaduka added the [Type] Code Quality Issues or PRs that relate to code quality label Jan 14, 2025
@justlevine
justlevine force-pushed the docs/fix-return-type-gutenberg_get_typography_value_and_unit() branch from 27d00e2 to 0cbf68d Compare April 18, 2025 22:56
westonruter and others added 2 commits October 24, 2026 21:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This matches `wp_get_typography_value_and_unit()` in WordPress core, which
has documented the return as `array|null` since r54260. Only the `@return`
tag is synced: core has since reworked the function body, so its
`@phpstan-*` shapes would not describe this implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@westonruter westonruter added the No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core label Oct 25, 2026
@westonruter

Copy link
Copy Markdown
Member

🤖 Comment by Claude Opus 5.5

Trunk was merged in, and 54b0ed2 changes the @return from ?array to array|null, with core's description ("… on success. null on failure."). This matches wp_get_typography_value_and_unit() in core, which has documented the return this way since r54260. Only the @return tag is synced, since core has since reworked the function body, so its @phpstan-* shapes and native ?array return type would not describe this implementation.

This resolves the three return.type errors reported at PHPStan level 5, with none introduced. Since core already documents the return correctly, the No Core Sync Required label was added.

@github-actions

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: justlevine <justlevine@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

Replace `gutenberg_get_typography_value_and_unit()` with
`wp_get_typography_value_and_unit()` as it stands in WordPress core after
r62719, which added types to the function and refactored its parsing:

* A fixed regular expression parses the value and unit, and the unit is
  then checked against the acceptable units with `in_array()`, rather than
  interpolating the units into the pattern unescaped.
* The value is cast to a float.
* `@phpstan-param` and `@phpstan-return` shapes are added, along with a
  native `?array` return type and an inline `@var` for the parsed options.

The docblock and the `_doing_it_wrong()` message now match core as well,
keeping Gutenberg's text domain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@westonruter westonruter added Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core and removed No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core labels Oct 25, 2026
@westonruter

westonruter commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

🤖 Comment by Claude Opus 5.5

Rather than syncing only the @return tag, c0ba7b1 now syncs the whole function with wp_get_typography_value_and_unit() as it stands in core after r62719 (Core-65143). That change parses the value and unit with a fixed regular expression and then checks the unit against the acceptable units with in_array(), instead of interpolating the units into the pattern unescaped. It also casts the value to a float and adds @phpstan-* shapes and a native ?array return type. The function is now identical to core's apart from the prefix and text domain, and WP_Block_Supports_Typography_Test passes. The label was changed to Backport from WordPress Core accordingly.

@westonruter

Copy link
Copy Markdown
Member

The only difference between the functions now:

--- core.txt	2026-10-25 13:30:54
+++ gutenberg.txt	2026-10-25 13:30:38
@@ -21,11 +21,11 @@
  * } $options
  * @phpstan-return array{ value: float, unit: non-empty-string }|null
  */
-function wp_get_typography_value_and_unit( $raw_value, $options = array() ): ?array {
+function gutenberg_get_typography_value_and_unit( $raw_value, $options = array() ): ?array {
 	if ( ! is_string( $raw_value ) && ! is_int( $raw_value ) && ! is_float( $raw_value ) ) {
 		_doing_it_wrong(
 			__FUNCTION__,
-			__( 'Raw size value must be a string, integer, or float.' ),
+			__( 'Raw size value must be a string, integer, or float.', 'gutenberg' ),
 			'6.1.0'
 		);
 		return null;

@westonruter
westonruter merged commit 8635a64 into WordPress:trunk Oct 25, 2026
79 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 25, 2026
@ingeniumed ingeniumed added the [Feature] Typography Font and typography-related issues and PRs label Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core [Feature] Typography Font and typography-related issues and PRs [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants