Skip to content

Commit 2008682

Browse files
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
1 parent d55ca12 commit 2008682

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/wp-includes/class-wp-object-cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ protected function is_valid_key( $key ) {
156156
$message = is_string( $key )
157157
? __( 'Cache key must not be an empty string.' )
158158
/* translators: %s: The type of the given cache key. */
159-
: sprintf( __( 'Cache key must be integer or non-empty string, %s given.' ), $type );
159+
: sprintf( __( 'Cache key must be an integer or a non-empty string, %s given.' ), $type );
160160

161161
_doing_it_wrong(
162162
sprintf( '%s::%s', __CLASS__, debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 )[1]['function'] ),

src/wp-includes/functions.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7034,24 +7034,28 @@ function _get_non_cached_ids( $object_ids, $cache_key ) {
70347034
}
70357035

70367036
/**
7037-
* Checks whether the given cache ID is either an integer or iterger-like strings.
7038-
* Both `16` and `"16"` are considered valid, other numeric types and numeric
7039-
* strings (`16.3` and `"16.3"`) are considered invalid.
7037+
* Checks whether the given cache ID is either an integer or an integer-like string.
7038+
*
7039+
* Both `16` and `"16"` are considered valid, other numeric types and numeric strings
7040+
* (`16.3` and `"16.3"`) are considered invalid.
70407041
*
70417042
* @since 6.3.0
70427043
*
7043-
* @param mixed $object_id The cache id to validate.
7044-
* @return bool Whether the given $object_id is a valid cache id.
7044+
* @param mixed $object_id The cache ID to validate.
7045+
* @return bool Whether the given $object_id is a valid cache ID.
70457046
*/
70467047
function _validate_cache_id( $object_id ) {
7047-
// Unfortunately filter_var() is considered an optional extension
7048+
/*
7049+
* filter_var() could be used here, but the `filter` PHP extension
7050+
* is considered optional and may not be available.
7051+
*/
70487052
if ( is_int( $object_id )
70497053
|| ( is_string( $object_id ) && (string) (int) $object_id === $object_id ) ) {
70507054
return true;
70517055
}
70527056

7053-
/* translators: %s: The type of the given object id. */
7054-
$message = sprintf( __( 'Object id must be integer, %s given.' ), gettype( $object_id ) );
7057+
/* translators: %s: The type of the given object ID. */
7058+
$message = sprintf( __( 'Object ID must be an integer, %s given.' ), gettype( $object_id ) );
70557059
_doing_it_wrong( '_get_non_cached_ids', $message, '6.3.0' );
70567060

70577061
return false;

tests/phpunit/tests/functions/getNonCachedIds.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @group cache
88
*
99
* @covers ::_get_non_cached_ids
10+
* @covers ::_validate_cache_id
1011
*/
1112
class Tests_Functions_GetNonCachedIds extends WP_UnitTestCase {
1213

@@ -28,7 +29,7 @@ public function test_uncached_valid_ids_should_be_unique() {
2829
*
2930
* @dataProvider data_valid_ids_should_be_returned_as_integers
3031
*
31-
* @param mixed $object_id The object id.
32+
* @param mixed $object_id The object ID.
3233
*/
3334
public function test_valid_ids_should_be_returned_as_integers( $object_id ) {
3435
$this->assertSame(
@@ -69,7 +70,7 @@ public function test_mix_of_valid_and_invalid_ids_should_return_the_valid_ids_an
6970
*
7071
* @dataProvider data_invalid_cache_ids_should_throw_a_notice
7172
*
72-
* @param mixed $object_id The object id.
73+
* @param mixed $object_id The object ID.
7374
*/
7475
public function test_invalid_cache_ids_should_throw_a_notice( $object_id ) {
7576
$this->setExpectedIncorrectUsage( '_get_non_cached_ids' );

0 commit comments

Comments
 (0)