Make WordPress Core

Changeset 62028


Ignore:
Timestamp:
03/14/2026 07:22:14 PM (2 weeks ago)
Author:
westonruter
Message:

Cache API: Address code quality issues with wp_cache_switch_to_blog().

This addresses 3 PHPStan errors at rule level 8:

  • arguments.count: Function wp_cache_switch_to_blog_fallback() invoked with 1 parameter, 0 required.
  • method.nonObject: Cannot call method switch_to_blog() on class-string|object.
  • missingType.return: Function wp_cache_switch_to_blog() has no return type specified.

Developed as subset of https://github.com/WordPress/wordpress-develop/pull/11151

Follow-up to r61760.

Props westonruter, johnjamesjacoby.
See #23290, #64238.

File:
1 edited

Legend:

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

    r61760 r62028  
    328328     * @param int $blog_id Site ID.
    329329     */
    330     function wp_cache_switch_to_blog( $blog_id ) {
     330    function wp_cache_switch_to_blog( $blog_id ): void {
    331331        global $wp_object_cache;
    332332
    333333        // Attempt to use the drop-in object cache method if it exists.
    334         if ( method_exists( $wp_object_cache, 'switch_to_blog' ) ) {
     334        if ( is_object( $wp_object_cache ) && method_exists( $wp_object_cache, 'switch_to_blog' ) ) {
    335335            $wp_object_cache->switch_to_blog( $blog_id );
    336336            return;
     
    341341         * for the new blog ID.
    342342         */
    343         wp_cache_switch_to_blog_fallback( $blog_id );
    344     }
    345 endif;
     343        wp_cache_switch_to_blog_fallback();
     344    }
     345endif;
Note: See TracChangeset for help on using the changeset viewer.