Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/object-cache.php

    r41289 r42343  
    307307    global $wp_object_cache;
    308308
    309     if ( func_num_args() > 4 )
     309    if ( func_num_args() > 4 ) {
    310310        return $wp_object_cache->get( $key, $group, $force, $found, '', false, $cache_cb, $cas_token );
    311     else
     311    } else {
    312312        return $wp_object_cache->get( $key, $group, $force, $found );
     313    }
    313314}
    314315
     
    332333 * @return bool|mixed               Cached object value.
    333334 */
    334 function wp_cache_get_by_key( $server_key, $key, $group = '', $force = false, &$found = null, $cache_cb = NULL, &$cas_token = NULL ) {
    335     global $wp_object_cache;
    336 
    337     if ( func_num_args() > 5 )
     335function wp_cache_get_by_key( $server_key, $key, $group = '', $force = false, &$found = null, $cache_cb = null, &$cas_token = null ) {
     336    global $wp_object_cache;
     337
     338    if ( func_num_args() > 5 ) {
    338339        return $wp_object_cache->getByKey( $server_key, $key, $group, $force, $found, $cache_cb, $cas_token );
    339     else
     340    } else {
    340341        return $wp_object_cache->getByKey( $server_key, $key, $group, $force, $found );
     342    }
    341343}
    342344
     
    352354 * @return bool                     Returns TRUE on success or FALSE on failure.
    353355 */
    354 function wp_cache_get_delayed( $keys, $groups = '', $with_cas = false, $value_cb = NULL ) {
     356function wp_cache_get_delayed( $keys, $groups = '', $with_cas = false, $value_cb = null ) {
    355357    global $wp_object_cache;
    356358    return $wp_object_cache->getDelayed( $keys, $groups, $with_cas, $value_cb );
     
    369371 * @return bool                     Returns TRUE on success or FALSE on failure.
    370372 */
    371 function wp_cache_get_delayed_by_key( $server_key, $keys, $groups = '', $with_cas = false, $value_cb = NULL ) {
     373function wp_cache_get_delayed_by_key( $server_key, $keys, $groups = '', $with_cas = false, $value_cb = null ) {
    372374    global $wp_object_cache;
    373375    return $wp_object_cache->getDelayedByKey( $server_key, $keys, $groups, $with_cas, $value_cb );
     
    387389 * @return bool|array               Returns the array of found items or FALSE on failure.
    388390 */
    389 function wp_cache_get_multi( $keys, $groups = '', &$cas_tokens = NULL, $flags = NULL ) {
    390     global $wp_object_cache;
    391 
    392     if ( func_num_args() > 2 )
     391function wp_cache_get_multi( $keys, $groups = '', &$cas_tokens = null, $flags = null ) {
     392    global $wp_object_cache;
     393
     394    if ( func_num_args() > 2 ) {
    393395        return $wp_object_cache->getMulti( $keys, $groups, '', $cas_tokens, $flags );
    394     else
     396    } else {
    395397        return $wp_object_cache->getMulti( $keys, $groups );
     398    }
    396399}
    397400
     
    410413 * @return bool|array               Returns the array of found items or FALSE on failure.
    411414 */
    412 function wp_cache_get_multi_by_key( $server_key, $keys, $groups = '', &$cas_tokens = NULL, $flags = NULL ) {
    413     global $wp_object_cache;
    414 
    415     if ( func_num_args() > 3 )
     415function wp_cache_get_multi_by_key( $server_key, $keys, $groups = '', &$cas_tokens = null, $flags = null ) {
     416    global $wp_object_cache;
     417
     418    if ( func_num_args() > 3 ) {
    416419        return $wp_object_cache->getMultiByKey( $server_key, $keys, $groups, $cas_tokens, $flags );
    417     else
     420    } else {
    418421        return $wp_object_cache->getMultiByKey( $server_key, $keys, $groups );
     422    }
    419423}
    420424
     
    819823     * @param   null    $persistent_id      To create an instance that persists between requests, use persistent_id to specify a unique ID for the instance.
    820824     */
    821     public function __construct( $persistent_id = NULL ) {
     825    public function __construct( $persistent_id = null ) {
    822826        global $memcached_servers, $blog_id, $table_prefix;
    823827
    824         if ( is_null( $persistent_id ) || ! is_string( $persistent_id ) )
     828        if ( is_null( $persistent_id ) || ! is_string( $persistent_id ) ) {
    825829            $this->m = new Memcached();
    826         else
     830        } else {
    827831            $this->m = new Memcached( $persistent_id );
    828 
    829         if ( isset( $memcached_servers ) )
     832        }
     833
     834        if ( isset( $memcached_servers ) ) {
    830835            $this->servers = $memcached_servers;
    831         else
     836        } else {
    832837            $this->servers = array( array( '127.0.0.1', 11211 ) );
     838        }
    833839
    834840        $this->addServers( $this->servers );
     
    838844         * multi single WP installations on the same server.
    839845         */
    840         if ( ! defined( 'WP_CACHE_KEY_SALT' ) )
     846        if ( ! defined( 'WP_CACHE_KEY_SALT' ) ) {
    841847            define( 'WP_CACHE_KEY_SALT', '' );
     848        }
    842849
    843850        // Assign global and blog prefixes for use with keys
    844851        if ( function_exists( 'is_multisite' ) ) {
    845852            $this->global_prefix = ( is_multisite() || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix;
    846             $this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':';
     853            $this->blog_prefix   = ( is_multisite() ? $blog_id : $table_prefix ) . ':';
    847854        }
    848855
     
    886893
    887894            // Add does not set the value if the key exists; mimic that here
    888             if ( isset( $this->cache[$derived_key] ) )
     895            if ( isset( $this->cache[ $derived_key ] ) ) {
    889896                return false;
     897            }
    890898
    891899            $this->add_to_internal_cache( $derived_key, $value );
     
    895903
    896904        // Save to Memcached
    897         if ( $byKey )
     905        if ( $byKey ) {
    898906            $result = $this->m->addByKey( $server_key, $derived_key, $value, $expiration );
    899         else
     907        } else {
    900908            $result = $this->m->add( $derived_key, $value, $expiration );
     909        }
    901910
    902911        // Store in runtime cache if add was successful
    903         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     912        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    904913            $this->add_to_internal_cache( $derived_key, $value );
     914        }
    905915
    906916        return $result;
     
    939949     */
    940950    public function addServer( $host, $port, $weight = 0 ) {
    941         $host = is_string( $host ) ? $host : '127.0.0.1';
    942         $port = is_numeric( $port ) && $port > 0 ? $port : 11211;
     951        $host   = is_string( $host ) ? $host : '127.0.0.1';
     952        $port   = is_numeric( $port ) && $port > 0 ? $port : 11211;
    943953        $weight = is_numeric( $weight ) && $weight > 0 ? $weight : 1;
    944954
     
    958968     */
    959969    public function addServers( $servers ) {
    960         if ( ! is_object( $this->m ) )
     970        if ( ! is_object( $this->m ) ) {
    961971            return false;
     972        }
    962973
    963974        return $this->m->addServers( $servers );
     
    984995     */
    985996    public function append( $key, $value, $group = 'default', $server_key = '', $byKey = false ) {
    986         if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) )
     997        if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) {
    987998            return false;
     999        }
    9881000
    9891001        $derived_key = $this->buildKey( $key, $group );
     
    9911003        // If group is a non-Memcached group, append to runtime cache value, not Memcached
    9921004        if ( in_array( $group, $this->no_mc_groups ) ) {
    993             if ( ! isset( $this->cache[$derived_key] ) )
     1005            if ( ! isset( $this->cache[ $derived_key ] ) ) {
    9941006                return false;
    995 
    996             $combined = $this->combine_values( $this->cache[$derived_key], $value, 'app' );
     1007            }
     1008
     1009            $combined = $this->combine_values( $this->cache[ $derived_key ], $value, 'app' );
    9971010            $this->add_to_internal_cache( $derived_key, $combined );
    9981011            return true;
     
    10001013
    10011014        // Append to Memcached value
    1002         if ( $byKey )
     1015        if ( $byKey ) {
    10031016            $result = $this->m->appendByKey( $server_key, $derived_key, $value );
    1004         else
     1017        } else {
    10051018            $result = $this->m->append( $derived_key, $value );
     1019        }
    10061020
    10071021        // Store in runtime cache if add was successful
    10081022        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    1009             $combined = $this->combine_values( $this->cache[$derived_key], $value, 'app' );
     1023            $combined = $this->combine_values( $this->cache[ $derived_key ], $value, 'app' );
    10101024            $this->add_to_internal_cache( $derived_key, $combined );
    10111025        }
     
    10681082
    10691083        // Save to Memcached
    1070         if ( $byKey )
     1084        if ( $byKey ) {
    10711085            $result = $this->m->casByKey( $cas_token, $server_key, $derived_key, $value, $expiration );
    1072         else
     1086        } else {
    10731087            $result = $this->m->cas( $cas_token, $derived_key, $value, $expiration );
     1088        }
    10741089
    10751090        // Store in runtime cache if cas was successful
    1076         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     1091        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    10771092            $this->add_to_internal_cache( $derived_key, $value );
     1093        }
    10781094
    10791095        return $result;
     
    11171133
    11181134            // Only decrement if the key already exists and value is 0 or greater (mimics memcached behavior)
    1119             if ( isset( $this->cache[$derived_key] ) && $this->cache[$derived_key] >= 0 ) {
     1135            if ( isset( $this->cache[ $derived_key ] ) && $this->cache[ $derived_key ] >= 0 ) {
    11201136
    11211137                // If numeric, subtract; otherwise, consider it 0 and do nothing
    1122                 if ( is_numeric( $this->cache[$derived_key] ) )
    1123                     $this->cache[$derived_key] -= (int) $offset;
    1124                 else
    1125                     $this->cache[$derived_key] = 0;
     1138                if ( is_numeric( $this->cache[ $derived_key ] ) ) {
     1139                    $this->cache[ $derived_key ] -= (int) $offset;
     1140                } else {
     1141                    $this->cache[ $derived_key ] = 0;
     1142                }
    11261143
    11271144                // Returned value cannot be less than 0
    1128                 if ( $this->cache[$derived_key] < 0 )
    1129                     $this->cache[$derived_key] = 0;
    1130 
    1131                 return $this->cache[$derived_key];
     1145                if ( $this->cache[ $derived_key ] < 0 ) {
     1146                    $this->cache[ $derived_key ] = 0;
     1147                }
     1148
     1149                return $this->cache[ $derived_key ];
    11321150            } else {
    11331151                return false;
     
    11371155        $result = $this->m->decrement( $derived_key, $offset );
    11381156
    1139         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     1157        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    11401158            $this->add_to_internal_cache( $derived_key, $result );
     1159        }
    11411160
    11421161        return $result;
     
    11801199        // Remove from no_mc_groups array
    11811200        if ( in_array( $group, $this->no_mc_groups ) ) {
    1182             if ( isset( $this->cache[$derived_key] ) )
    1183                 unset( $this->cache[$derived_key] );
     1201            if ( isset( $this->cache[ $derived_key ] ) ) {
     1202                unset( $this->cache[ $derived_key ] );
     1203            }
    11841204
    11851205            return true;
    11861206        }
    11871207
    1188         if ( $byKey )
     1208        if ( $byKey ) {
    11891209            $result = $this->m->deleteByKey( $server_key, $derived_key, $time );
    1190         else
     1210        } else {
    11911211            $result = $this->m->delete( $derived_key, $time );
    1192 
    1193         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
    1194             unset( $this->cache[$derived_key] );
     1212        }
     1213
     1214        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
     1215            unset( $this->cache[ $derived_key ] );
     1216        }
    11951217
    11961218        return $result;
     
    12361258     */
    12371259    public function fetchAll() {
    1238         return $this->m->fetchAll();
     1260        return $this->m->fetchAll();
    12391261    }
    12401262
     
    12511273
    12521274        // Only reset the runtime cache if memcached was properly flushed
    1253         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     1275        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    12541276            $this->cache = array();
     1277        }
    12551278
    12561279        return $result;
     
    12811304     * @return  bool|mixed                  Cached object value.
    12821305     */
    1283     public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $byKey = false, $cache_cb = NULL, &$cas_token = NULL ) {
     1306    public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $byKey = false, $cache_cb = null, &$cas_token = null ) {
    12841307        $derived_key = $this->buildKey( $key, $group );
    12851308
     
    12891312        // If either $cache_db, or $cas_token is set, must hit Memcached and bypass runtime cache
    12901313        if ( func_num_args() > 6 && ! in_array( $group, $this->no_mc_groups ) ) {
    1291             if ( $byKey )
     1314            if ( $byKey ) {
    12921315                $value = $this->m->getByKey( $server_key, $derived_key, $cache_cb, $cas_token );
    1293             else
     1316            } else {
    12941317                $value = $this->m->get( $derived_key, $cache_cb, $cas_token );
     1318            }
    12951319        } else {
    1296             if ( isset( $this->cache[$derived_key] ) ) {
     1320            if ( isset( $this->cache[ $derived_key ] ) ) {
    12971321                $found = true;
    1298                 return is_object( $this->cache[$derived_key] ) ? clone $this->cache[$derived_key] : $this->cache[$derived_key];
     1322                return is_object( $this->cache[ $derived_key ] ) ? clone $this->cache[ $derived_key ] : $this->cache[ $derived_key ];
    12991323            } elseif ( in_array( $group, $this->no_mc_groups ) ) {
    13001324                return false;
    13011325            } else {
    1302                 if ( $byKey )
     1326                if ( $byKey ) {
    13031327                    $value = $this->m->getByKey( $server_key, $derived_key );
    1304                 else
     1328                } else {
    13051329                    $value = $this->m->get( $derived_key );
     1330                }
    13061331            }
    13071332        }
     
    13381363     * @return  bool|mixed                  Cached object value.
    13391364     */
    1340     public function getByKey( $server_key, $key, $group = 'default', $force = false, &$found = null, $cache_cb = NULL, &$cas_token = NULL ) {
     1365    public function getByKey( $server_key, $key, $group = 'default', $force = false, &$found = null, $cache_cb = null, &$cas_token = null ) {
    13411366        /**
    13421367         * Need to be careful how "get" is called. If you send $cache_cb, and $cas_token, it will hit memcached.
    13431368         * Only send those args if they were sent to this function.
    13441369         */
    1345         if ( func_num_args() > 5 )
     1370        if ( func_num_args() > 5 ) {
    13461371            return $this->get( $key, $group, $force, $found, $server_key, true, $cache_cb, $cas_token );
    1347         else
     1372        } else {
    13481373            return $this->get( $key, $group, $force, $found, $server_key, true );
     1374        }
    13491375    }
    13501376
     
    13601386     * @return  bool                        Returns TRUE on success or FALSE on failure.
    13611387     */
    1362     public function getDelayed( $keys, $groups = 'default', $with_cas = false, $value_cb = NULL ) {
     1388    public function getDelayed( $keys, $groups = 'default', $with_cas = false, $value_cb = null ) {
    13631389        $derived_keys = $this->buildKeys( $keys, $groups );
    13641390        return $this->m->getDelayed( $derived_keys, $with_cas, $value_cb );
     
    13771403     * @return  bool                        Returns TRUE on success or FALSE on failure.
    13781404     */
    1379     public function getDelayedByKey( $server_key, $keys, $groups = 'default', $with_cas = false, $value_cb = NULL ) {
     1405    public function getDelayedByKey( $server_key, $keys, $groups = 'default', $with_cas = false, $value_cb = null ) {
    13801406        $derived_keys = $this->buildKeys( $keys, $groups );
    13811407        return $this->m->getDelayedByKey( $server_key, $derived_keys, $with_cas, $value_cb );
     
    13961422     * @return  bool|array                  Returns the array of found items or FALSE on failure.
    13971423     */
    1398     public function getMulti( $keys, $groups = 'default', $server_key = '', &$cas_tokens = NULL, $flags = NULL ) {
     1424    public function getMulti( $keys, $groups = 'default', $server_key = '', &$cas_tokens = null, $flags = null ) {
    13991425        $derived_keys = $this->buildKeys( $keys, $groups );
    14001426
     
    14051431         */
    14061432        if ( func_num_args() > 3 && ! $this->contains_no_mc_group( $groups ) ) {
    1407             if ( ! empty( $server_key ) )
     1433            if ( ! empty( $server_key ) ) {
    14081434                $values = $this->m->getMultiByKey( $server_key, $derived_keys, $cas_tokens, $flags );
    1409             else
     1435            } else {
    14101436                $values = $this->m->getMulti( $derived_keys, $cas_tokens, $flags );
     1437            }
    14111438        } else {
    1412             $values = array();
     1439            $values      = array();
    14131440            $need_to_get = array();
    14141441
    14151442            // Pull out values from runtime cache, or mark for retrieval
    14161443            foreach ( $derived_keys as $key ) {
    1417                 if ( isset( $this->cache[$key] ) )
    1418                     $values[$key] = $this->cache[$key];
    1419                 else
    1420                     $need_to_get[$key] = $key;
     1444                if ( isset( $this->cache[ $key ] ) ) {
     1445                    $values[ $key ] = $this->cache[ $key ];
     1446                } else {
     1447                    $need_to_get[ $key ] = $key;
     1448                }
    14211449            }
    14221450
    14231451            // Get those keys not found in the runtime cache
    14241452            if ( ! empty( $need_to_get ) ) {
    1425                 if ( ! empty( $server_key ) )
     1453                if ( ! empty( $server_key ) ) {
    14261454                    $result = $this->m->getMultiByKey( $server_key, array_keys( $need_to_get ) );
    1427                 else
     1455                } else {
    14281456                    $result = $this->m->getMulti( array_keys( $need_to_get ) );
     1457                }
    14291458            }
    14301459
    14311460            // Merge with values found in runtime cache
    1432             if ( isset( $result ) && Memcached::RES_SUCCESS === $this->getResultCode() )
     1461            if ( isset( $result ) && Memcached::RES_SUCCESS === $this->getResultCode() ) {
    14331462                $values = array_merge( $values, $result );
     1463            }
    14341464
    14351465            // If order should be preserved, reorder now
     
    14381468
    14391469                foreach ( $derived_keys as $key ) {
    1440                     if ( isset( $values[$key] ) )
    1441                         $ordered_values[$key] = $values[$key];
     1470                    if ( isset( $values[ $key ] ) ) {
     1471                        $ordered_values[ $key ] = $values[ $key ];
     1472                    }
    14421473                }
    14431474
     
    14671498     * @return  bool|array                  Returns the array of found items or FALSE on failure.
    14681499     */
    1469     public function getMultiByKey( $server_key, $keys, $groups = 'default', &$cas_tokens = NULL, $flags = NULL ) {
     1500    public function getMultiByKey( $server_key, $keys, $groups = 'default', &$cas_tokens = null, $flags = null ) {
    14701501        /**
    14711502         * Need to be careful how "getMulti" is called. If you send $cache_cb, and $cas_token, it will hit memcached.
    14721503         * Only send those args if they were sent to this function.
    14731504         */
    1474         if ( func_num_args() > 3 )
     1505        if ( func_num_args() > 3 ) {
    14751506            return $this->getMulti( $keys, $groups, $server_key, $cas_tokens, $flags );
    1476         else
     1507        } else {
    14771508            return $this->getMulti( $keys, $groups, $server_key );
     1509        }
    14781510    }
    14791511
     
    14981530     */
    14991531    public function getResultCode() {
    1500         return $this->m->getResultCode();
     1532        return $this->m->getResultCode();
    15011533    }
    15021534
     
    15091541     */
    15101542    public function getResultMessage() {
    1511         return $this->m->getResultMessage();
     1543        return $this->m->getResultMessage();
    15121544    }
    15131545
     
    15361568
    15371569    /**
    1538     * Get server pool statistics.
     1570    * Get server pool statistics.
    15391571     *
    15401572     * @link    http://www.php.net/manual/en/memcached.getstats.php
     
    15741606
    15751607            // Only increment if the key already exists and the number is currently 0 or greater (mimics memcached behavior)
    1576             if ( isset( $this->cache[$derived_key] ) &&  $this->cache[$derived_key] >= 0 ) {
     1608            if ( isset( $this->cache[ $derived_key ] ) && $this->cache[ $derived_key ] >= 0 ) {
    15771609
    15781610                // If numeric, add; otherwise, consider it 0 and do nothing
    1579                 if ( is_numeric( $this->cache[$derived_key] ) )
    1580                     $this->cache[$derived_key] += (int) $offset;
    1581                 else
    1582                     $this->cache[$derived_key] = 0;
     1611                if ( is_numeric( $this->cache[ $derived_key ] ) ) {
     1612                    $this->cache[ $derived_key ] += (int) $offset;
     1613                } else {
     1614                    $this->cache[ $derived_key ] = 0;
     1615                }
    15831616
    15841617                // Returned value cannot be less than 0
    1585                 if ( $this->cache[$derived_key] < 0 )
    1586                     $this->cache[$derived_key] = 0;
    1587 
    1588                 return $this->cache[$derived_key];
     1618                if ( $this->cache[ $derived_key ] < 0 ) {
     1619                    $this->cache[ $derived_key ] = 0;
     1620                }
     1621
     1622                return $this->cache[ $derived_key ];
    15891623            } else {
    15901624                return false;
     
    15941628        $result = $this->m->increment( $derived_key, $offset );
    15951629
    1596         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     1630        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    15971631            $this->add_to_internal_cache( $derived_key, $result );
     1632        }
    15981633
    15991634        return $result;
     
    16371672     */
    16381673    public function prepend( $key, $value, $group = 'default', $server_key = '', $byKey = false ) {
    1639         if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) )
     1674        if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) {
    16401675            return false;
     1676        }
    16411677
    16421678        $derived_key = $this->buildKey( $key, $group );
     
    16441680        // If group is a non-Memcached group, prepend to runtime cache value, not Memcached
    16451681        if ( in_array( $group, $this->no_mc_groups ) ) {
    1646             if ( ! isset( $this->cache[$derived_key] ) )
     1682            if ( ! isset( $this->cache[ $derived_key ] ) ) {
    16471683                return false;
    1648 
    1649             $combined = $this->combine_values( $this->cache[$derived_key], $value, 'pre' );
     1684            }
     1685
     1686            $combined = $this->combine_values( $this->cache[ $derived_key ], $value, 'pre' );
    16501687            $this->add_to_internal_cache( $derived_key, $combined );
    16511688            return true;
     
    16531690
    16541691        // Append to Memcached value
    1655         if ( $byKey )
     1692        if ( $byKey ) {
    16561693            $result = $this->m->prependByKey( $server_key, $derived_key, $value );
    1657         else
     1694        } else {
    16581695            $result = $this->m->prepend( $derived_key, $value );
     1696        }
    16591697
    16601698        // Store in runtime cache if add was successful
    16611699        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    1662             $combined = $this->combine_values( $this->cache[$derived_key], $value, 'pre' );
     1700            $combined = $this->combine_values( $this->cache[ $derived_key ], $value, 'pre' );
    16631701            $this->add_to_internal_cache( $derived_key, $combined );
    16641702        }
     
    17141752
    17151753            // Replace won't save unless the key already exists; mimic this behavior here
    1716             if ( ! isset( $this->cache[$derived_key] ) )
     1754            if ( ! isset( $this->cache[ $derived_key ] ) ) {
    17171755                return false;
    1718 
    1719             $this->cache[$derived_key] = $value;
     1756            }
     1757
     1758            $this->cache[ $derived_key ] = $value;
    17201759            return true;
    17211760        }
    17221761
    17231762        // Save to Memcached
    1724         if ( $byKey )
     1763        if ( $byKey ) {
    17251764            $result = $this->m->replaceByKey( $server_key, $derived_key, $value, $expiration );
    1726         else
     1765        } else {
    17271766            $result = $this->m->replace( $derived_key, $value, $expiration );
     1767        }
    17281768
    17291769        // Store in runtime cache if add was successful
    1730         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     1770        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    17311771            $this->add_to_internal_cache( $derived_key, $value );
     1772        }
    17321773
    17331774        return $result;
     
    17861827
    17871828        // Store in runtime cache if add was successful
    1788         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     1829        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    17891830            $this->add_to_internal_cache( $derived_key, $value );
     1831        }
    17901832
    17911833        return $result;
     
    18431885            if ( in_array( $key_pieces[1], $this->no_mc_groups ) ) {
    18441886                $this->add_to_internal_cache( $derived_key, $value );
    1845                 unset( $derived_items[$derived_key] );
     1887                unset( $derived_items[ $derived_key ] );
    18461888            }
    18471889        }
    18481890
    18491891        // Save to memcached
    1850         if ( $byKey )
     1892        if ( $byKey ) {
    18511893            $result = $this->m->setMultiByKey( $server_key, $derived_items, $expiration );
    1852         else
     1894        } else {
    18531895            $result = $this->m->setMulti( $derived_items, $expiration );
     1896        }
    18541897
    18551898        // Store in runtime cache if add was successful
    1856         if ( Memcached::RES_SUCCESS === $this->getResultCode() )
     1899        if ( Memcached::RES_SUCCESS === $this->getResultCode() ) {
    18571900            $this->cache = array_merge( $this->cache, $derived_items );
     1901        }
    18581902
    18591903        return $result;
     
    19051949     */
    19061950    public function buildKey( $key, $group = 'default' ) {
    1907         if ( empty( $group ) )
     1951        if ( empty( $group ) ) {
    19081952            $group = 'default';
    1909 
    1910         if ( false !== array_search( $group, $this->global_groups ) )
     1953        }
     1954
     1955        if ( false !== array_search( $group, $this->global_groups ) ) {
    19111956            $prefix = $this->global_prefix;
    1912         else
     1957        } else {
    19131958            $prefix = $this->blog_prefix;
     1959        }
    19141960
    19151961        return preg_replace( '/\s+/', '', WP_CACHE_KEY_SALT . "$prefix$group:$key" );
     
    19361982
    19371983        // If strings sent, convert to arrays for proper handling
    1938         if ( ! is_array( $groups ) )
     1984        if ( ! is_array( $groups ) ) {
    19391985            $groups = (array) $groups;
    1940 
    1941         if ( ! is_array( $keys ) )
     1986        }
     1987
     1988        if ( ! is_array( $keys ) ) {
    19421989            $keys = (array) $keys;
     1990        }
    19431991
    19441992        // If we have equal numbers of keys and groups, merge $keys[n] and $group[n]
    19451993        if ( count( $keys ) == count( $groups ) ) {
    19461994            for ( $i = 0; $i < count( $keys ); $i++ ) {
    1947                 $derived_keys[] = $this->buildKey( $keys[$i], $groups[$i] );
     1995                $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] );
    19481996            }
    19491997
    1950         // If more keys are received than groups, merge $keys[n] and $group[n] until no more group are left; remaining groups are 'default'
     1998            // If more keys are received than groups, merge $keys[n] and $group[n] until no more group are left; remaining groups are 'default'
    19511999        } elseif ( count( $keys ) > count( $groups ) ) {
    19522000            for ( $i = 0; $i < count( $keys ); $i++ ) {
    1953                 if ( isset( $groups[$i] ) )
    1954                     $derived_keys[] = $this->buildKey( $keys[$i], $groups[$i] );
    1955                 elseif ( count( $groups ) == 1 )
    1956                     $derived_keys[] = $this->buildKey( $keys[$i], $groups[0] );
    1957                 else
    1958                     $derived_keys[] = $this->buildKey( $keys[$i], 'default' );
     2001                if ( isset( $groups[ $i ] ) ) {
     2002                    $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] );
     2003                } elseif ( count( $groups ) == 1 ) {
     2004                    $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[0] );
     2005                } else {
     2006                    $derived_keys[] = $this->buildKey( $keys[ $i ], 'default' );
     2007                }
    19592008            }
    19602009        }
     
    19972046
    19982047        // Combine the values based on direction of the "pend"
    1999         if ( 'pre' == $direction )
     2048        if ( 'pre' == $direction ) {
    20002049            $combined = $pended . $original;
    2001         else
     2050        } else {
    20022051            $combined = $original . $pended;
     2052        }
    20032053
    20042054        // Cast type of combined value
     
    20192069        }
    20202070
    2021         $this->cache[$derived_key] = $value;
     2071        $this->cache[ $derived_key ] = $value;
    20222072    }
    20232073
     
    20292079     */
    20302080    public function contains_no_mc_group( $groups ) {
    2031         if ( is_scalar( $groups ) )
     2081        if ( is_scalar( $groups ) ) {
    20322082            return in_array( $groups, $this->no_mc_groups );
    2033 
    2034         if ( ! is_array( $groups ) )
     2083        }
     2084
     2085        if ( ! is_array( $groups ) ) {
    20352086            return false;
     2087        }
    20362088
    20372089        foreach ( $groups as $group ) {
    2038             if ( in_array( $group, $this->no_mc_groups ) )
     2090            if ( in_array( $group, $this->no_mc_groups ) ) {
    20392091                return true;
     2092            }
    20402093        }
    20412094
     
    20532106     */
    20542107    public function add_global_groups( $groups ) {
    2055         if ( ! is_array( $groups ) )
     2108        if ( ! is_array( $groups ) ) {
    20562109            $groups = (array) $groups;
    2057 
    2058         $this->global_groups = array_merge( $this->global_groups, $groups);
     2110        }
     2111
     2112        $this->global_groups = array_merge( $this->global_groups, $groups );
    20592113        $this->global_groups = array_unique( $this->global_groups );
    20602114    }
     
    20702124     */
    20712125    public function add_non_persistent_groups( $groups ) {
    2072         if ( ! is_array( $groups ) )
     2126        if ( ! is_array( $groups ) ) {
    20732127            $groups = (array) $groups;
     2128        }
    20742129
    20752130        $this->no_mc_groups = array_merge( $this->no_mc_groups, $groups );
     
    20872142        $derived_key = $this->buildKey( $key, $group );
    20882143
    2089         if ( isset( $this->cache[$derived_key] ) )
    2090             return $this->cache[$derived_key];
     2144        if ( isset( $this->cache[ $derived_key ] ) ) {
     2145            return $this->cache[ $derived_key ];
     2146        }
    20912147
    20922148        return false;
Note: See TracChangeset for help on using the changeset viewer.