Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 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/src/wp-includes/cache.php

    r41688 r42343  
    8282    global $wp_object_cache;
    8383
    84     return $wp_object_cache->delete($key, $group);
     84    return $wp_object_cache->delete( $key, $group );
    8585}
    8686
     
    116116 *                            Disambiguates a return of false, a storable value. Default null.
    117117 * @return bool|mixed False on failure to retrieve contents or the cache
    118  *                    contents on success
     118 *                    contents on success
    119119 */
    120120function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {
     
    391391     * @uses WP_Object_Cache::_exists() Checks to see if the cache already has data.
    392392     * @uses WP_Object_Cache::set()     Sets the data after the checking the cache
    393      *                                  contents existence.
     393     *                                  contents existence.
    394394     *
    395395     * @param int|string $key    What to call the contents in the cache.
     
    400400     */
    401401    public function add( $key, $data, $group = 'default', $expire = 0 ) {
    402         if ( wp_suspend_cache_addition() )
     402        if ( wp_suspend_cache_addition() ) {
    403403            return false;
    404 
    405         if ( empty( $group ) )
     404        }
     405
     406        if ( empty( $group ) ) {
    406407            $group = 'default';
     408        }
    407409
    408410        $id = $key;
    409         if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
     411        if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
    410412            $id = $this->blog_prefix . $key;
    411 
    412         if ( $this->_exists( $id, $group ) )
     413        }
     414
     415        if ( $this->_exists( $id, $group ) ) {
    413416            return false;
     417        }
    414418
    415419        return $this->set( $key, $data, $group, (int) $expire );
     
    426430        $groups = (array) $groups;
    427431
    428         $groups = array_fill_keys( $groups, true );
     432        $groups              = array_fill_keys( $groups, true );
    429433        $this->global_groups = array_merge( $this->global_groups, $groups );
    430434    }
     
    441445     */
    442446    public function decr( $key, $offset = 1, $group = 'default' ) {
    443         if ( empty( $group ) )
     447        if ( empty( $group ) ) {
    444448            $group = 'default';
    445 
    446         if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
     449        }
     450
     451        if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
    447452            $key = $this->blog_prefix . $key;
    448 
    449         if ( ! $this->_exists( $key, $group ) )
     453        }
     454
     455        if ( ! $this->_exists( $key, $group ) ) {
    450456            return false;
    451 
    452         if ( ! is_numeric( $this->cache[ $group ][ $key ] ) )
     457        }
     458
     459        if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
    453460            $this->cache[ $group ][ $key ] = 0;
     461        }
    454462
    455463        $offset = (int) $offset;
     
    457465        $this->cache[ $group ][ $key ] -= $offset;
    458466
    459         if ( $this->cache[ $group ][ $key ] < 0 )
     467        if ( $this->cache[ $group ][ $key ] < 0 ) {
    460468            $this->cache[ $group ][ $key ] = 0;
     469        }
    461470
    462471        return $this->cache[ $group ][ $key ];
     
    476485     */
    477486    public function delete( $key, $group = 'default', $deprecated = false ) {
    478         if ( empty( $group ) )
     487        if ( empty( $group ) ) {
    479488            $group = 'default';
    480 
    481         if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
     489        }
     490
     491        if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
    482492            $key = $this->blog_prefix . $key;
    483 
    484         if ( ! $this->_exists( $key, $group ) )
     493        }
     494
     495        if ( ! $this->_exists( $key, $group ) ) {
    485496            return false;
    486 
    487         unset( $this->cache[$group][$key] );
     497        }
     498
     499        unset( $this->cache[ $group ][ $key ] );
    488500        return true;
    489501    }
     
    522534     */
    523535    public function get( $key, $group = 'default', $force = false, &$found = null ) {
    524         if ( empty( $group ) )
     536        if ( empty( $group ) ) {
    525537            $group = 'default';
    526 
    527         if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
     538        }
     539
     540        if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
    528541            $key = $this->blog_prefix . $key;
     542        }
    529543
    530544        if ( $this->_exists( $key, $group ) ) {
    531             $found = true;
     545            $found             = true;
    532546            $this->cache_hits += 1;
    533             if ( is_object($this->cache[$group][$key]) )
    534                 return clone $this->cache[$group][$key];
    535             else
    536                 return $this->cache[$group][$key];
    537         }
    538 
    539         $found = false;
     547            if ( is_object( $this->cache[ $group ][ $key ] ) ) {
     548                return clone $this->cache[ $group ][ $key ];
     549            } else {
     550                return $this->cache[ $group ][ $key ];
     551            }
     552        }
     553
     554        $found               = false;
    540555        $this->cache_misses += 1;
    541556        return false;
     
    553568     */
    554569    public function incr( $key, $offset = 1, $group = 'default' ) {
    555         if ( empty( $group ) )
     570        if ( empty( $group ) ) {
    556571            $group = 'default';
    557 
    558         if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
     572        }
     573
     574        if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
    559575            $key = $this->blog_prefix . $key;
    560 
    561         if ( ! $this->_exists( $key, $group ) )
     576        }
     577
     578        if ( ! $this->_exists( $key, $group ) ) {
    562579            return false;
    563 
    564         if ( ! is_numeric( $this->cache[ $group ][ $key ] ) )
     580        }
     581
     582        if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
    565583            $this->cache[ $group ][ $key ] = 0;
     584        }
    566585
    567586        $offset = (int) $offset;
     
    569588        $this->cache[ $group ][ $key ] += $offset;
    570589
    571         if ( $this->cache[ $group ][ $key ] < 0 )
     590        if ( $this->cache[ $group ][ $key ] < 0 ) {
    572591            $this->cache[ $group ][ $key ] = 0;
     592        }
    573593
    574594        return $this->cache[ $group ][ $key ];
     
    589609     */
    590610    public function replace( $key, $data, $group = 'default', $expire = 0 ) {
    591         if ( empty( $group ) )
     611        if ( empty( $group ) ) {
    592612            $group = 'default';
     613        }
    593614
    594615        $id = $key;
    595         if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
     616        if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
    596617            $id = $this->blog_prefix . $key;
    597 
    598         if ( ! $this->_exists( $id, $group ) )
     618        }
     619
     620        if ( ! $this->_exists( $id, $group ) ) {
    599621            return false;
     622        }
    600623
    601624        return $this->set( $key, $data, $group, (int) $expire );
     
    615638        // Clear out non-global caches since the blog ID has changed.
    616639        foreach ( array_keys( $this->cache ) as $group ) {
    617             if ( ! isset( $this->global_groups[ $group ] ) )
     640            if ( ! isset( $this->global_groups[ $group ] ) ) {
    618641                unset( $this->cache[ $group ] );
     642            }
    619643        }
    620644    }
     
    641665     */
    642666    public function set( $key, $data, $group = 'default', $expire = 0 ) {
    643         if ( empty( $group ) )
     667        if ( empty( $group ) ) {
    644668            $group = 'default';
    645 
    646         if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) )
     669        }
     670
     671        if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
    647672            $key = $this->blog_prefix . $key;
    648 
    649         if ( is_object( $data ) )
     673        }
     674
     675        if ( is_object( $data ) ) {
    650676            $data = clone $data;
    651 
    652         $this->cache[$group][$key] = $data;
     677        }
     678
     679        $this->cache[ $group ][ $key ] = $data;
    653680        return true;
    654681    }
     
    663690     */
    664691    public function stats() {
    665         echo "<p>";
     692        echo '<p>';
    666693        echo "<strong>Cache Hits:</strong> {$this->cache_hits}<br />";
    667694        echo "<strong>Cache Misses:</strong> {$this->cache_misses}<br />";
    668         echo "</p>";
     695        echo '</p>';
    669696        echo '<ul>';
    670         foreach ($this->cache as $group => $cache) {
     697        foreach ( $this->cache as $group => $cache ) {
    671698            echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
    672699        }
     
    684711     */
    685712    public function switch_to_blog( $blog_id ) {
    686         $blog_id = (int) $blog_id;
     713        $blog_id           = (int) $blog_id;
    687714        $this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
    688715    }
     
    707734     */
    708735    public function __construct() {
    709         $this->multisite = is_multisite();
    710         $this->blog_prefix =  $this->multisite ? get_current_blog_id() . ':' : '';
    711 
     736        $this->multisite   = is_multisite();
     737        $this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : '';
    712738
    713739        /**
Note: See TracChangeset for help on using the changeset viewer.