From 200868214a1ae0a108dac491677ba82e7541fc8d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 14 Mar 2023 16:53:07 +0000 Subject: [PATCH] Docs: Fix typo in `_validate_cache_id()` description. Includes: * Capitalizing "ID" in a consistent way. * Expanding the comment on not using `filter_var()`. * Adding a `@covers` tag for the function in unit tests. * Minor tweak to the `_doing_it_wrong()` message. Follow-up to [53818], [55543]. See #57593. git-svn-id: https://develop.svn.wordpress.org/trunk@55549 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-object-cache.php | 2 +- src/wp-includes/functions.php | 20 +++++++++++-------- .../tests/functions/getNonCachedIds.php | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/class-wp-object-cache.php b/src/wp-includes/class-wp-object-cache.php index cd84b17753..8136ea3ad9 100644 --- a/src/wp-includes/class-wp-object-cache.php +++ b/src/wp-includes/class-wp-object-cache.php @@ -156,7 +156,7 @@ class WP_Object_Cache { $message = is_string( $key ) ? __( 'Cache key must not be an empty string.' ) /* translators: %s: The type of the given cache key. */ - : sprintf( __( 'Cache key must be integer or non-empty string, %s given.' ), $type ); + : sprintf( __( 'Cache key must be an integer or a non-empty string, %s given.' ), $type ); _doing_it_wrong( sprintf( '%s::%s', __CLASS__, debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1]['function'] ), diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index e3e281b1d6..2112323704 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -7034,24 +7034,28 @@ function _get_non_cached_ids( $object_ids, $cache_key ) { } /** - * Checks whether the given cache ID is either an integer or iterger-like strings. - * Both `16` and `"16"` are considered valid, other numeric types and numeric - * strings (`16.3` and `"16.3"`) are considered invalid. + * Checks whether the given cache ID is either an integer or an integer-like string. + * + * Both `16` and `"16"` are considered valid, other numeric types and numeric strings + * (`16.3` and `"16.3"`) are considered invalid. * * @since 6.3.0 * - * @param mixed $object_id The cache id to validate. - * @return bool Whether the given $object_id is a valid cache id. + * @param mixed $object_id The cache ID to validate. + * @return bool Whether the given $object_id is a valid cache ID. */ function _validate_cache_id( $object_id ) { - // Unfortunately filter_var() is considered an optional extension + /* + * filter_var() could be used here, but the `filter` PHP extension + * is considered optional and may not be available. + */ if ( is_int( $object_id ) || ( is_string( $object_id ) && (string) (int) $object_id === $object_id ) ) { return true; } - /* translators: %s: The type of the given object id. */ - $message = sprintf( __( 'Object id must be integer, %s given.' ), gettype( $object_id ) ); + /* translators: %s: The type of the given object ID. */ + $message = sprintf( __( 'Object ID must be an integer, %s given.' ), gettype( $object_id ) ); _doing_it_wrong( '_get_non_cached_ids', $message, '6.3.0' ); return false; diff --git a/tests/phpunit/tests/functions/getNonCachedIds.php b/tests/phpunit/tests/functions/getNonCachedIds.php index 300477d8ad..d8df0e11a6 100644 --- a/tests/phpunit/tests/functions/getNonCachedIds.php +++ b/tests/phpunit/tests/functions/getNonCachedIds.php @@ -7,6 +7,7 @@ * @group cache * * @covers ::_get_non_cached_ids + * @covers ::_validate_cache_id */ class Tests_Functions_GetNonCachedIds extends WP_UnitTestCase { @@ -28,7 +29,7 @@ class Tests_Functions_GetNonCachedIds extends WP_UnitTestCase { * * @dataProvider data_valid_ids_should_be_returned_as_integers * - * @param mixed $object_id The object id. + * @param mixed $object_id The object ID. */ public function test_valid_ids_should_be_returned_as_integers( $object_id ) { $this->assertSame( @@ -69,7 +70,7 @@ class Tests_Functions_GetNonCachedIds extends WP_UnitTestCase { * * @dataProvider data_invalid_cache_ids_should_throw_a_notice * - * @param mixed $object_id The object id. + * @param mixed $object_id The object ID. */ public function test_invalid_cache_ids_should_throw_a_notice( $object_id ) { $this->setExpectedIncorrectUsage( '_get_non_cached_ids' );