Make WordPress Core

Changeset 55549


Ignore:
Timestamp:
03/14/2023 04:53:07 PM (15 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-object-cache.php

    r54318 r55549  
    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(
  • trunk/src/wp-includes/functions.php

    r55543 r55549  
    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 */
    70467047function _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 ) ) {
     
    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
  • trunk/tests/phpunit/tests/functions/getNonCachedIds.php

    r55543 r55549  
    88 *
    99 * @covers ::_get_non_cached_ids
     10 * @covers ::_validate_cache_id
    1011 */
    1112class Tests_Functions_GetNonCachedIds extends WP_UnitTestCase {
     
    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 ) {
     
    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 ) {
Note: See TracChangeset for help on using the changeset viewer.