Make WordPress Core


Ignore:
Timestamp:
07/08/2019 12:55:20 AM (6 years ago)
Author:
pento
Message:

Coding Standards: Fix the remaining issues in /tests.

All PHP files in /tests now conform to the PHP coding standards, or have exceptions appropriately marked.

Travis now also runs phpcs on the /tests directory, any future changes to these files must conform entirely to the WordPress PHP coding standards. 🎉

See #47632.

File:
1 edited

Legend:

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

    r45580 r45607  
    873873     * @param   int         $expiration     The expiration time, defaults to 0.
    874874     * @param   string      $server_key     The key identifying the server to store the value on.
    875      * @param   bool        $byKey          True to store in internal cache by key; false to not store by key
     875     * @param   bool        $by_key         True to store in internal cache by key; false to not store by key
    876876     * @return  bool                        Returns TRUE on success or FALSE on failure.
    877877     */
    878     public function add( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) {
     878    public function add( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
    879879        /*
    880880         * Ensuring that wp_suspend_cache_addition is defined before calling, because sometimes an advanced-cache.php
     
    891891
    892892        // If group is a non-Memcached group, save to runtime cache, not Memcached
    893         if ( in_array( $group, $this->no_mc_groups ) ) {
     893        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    894894
    895895            // Add does not set the value if the key exists; mimic that here
     
    904904
    905905        // Save to Memcached
    906         if ( $byKey ) {
     906        if ( $by_key ) {
    907907            $result = $this->m->addByKey( $server_key, $derived_key, $value, $expiration );
    908908        } else {
     
    992992     * @param   string      $group          The group value appended to the $key.
    993993     * @param   string      $server_key     The key identifying the server to store the value on.
    994      * @param   bool        $byKey          True to store in internal cache by key; false to not store by key
     994     * @param   bool        $by_key         True to store in internal cache by key; false to not store by key
    995995     * @return  bool                        Returns TRUE on success or FALSE on failure.
    996996     */
    997     public function append( $key, $value, $group = 'default', $server_key = '', $byKey = false ) {
     997    public function append( $key, $value, $group = 'default', $server_key = '', $by_key = false ) {
    998998        if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) {
    999999            return false;
     
    10031003
    10041004        // If group is a non-Memcached group, append to runtime cache value, not Memcached
    1005         if ( in_array( $group, $this->no_mc_groups ) ) {
     1005        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    10061006            if ( ! isset( $this->cache[ $derived_key ] ) ) {
    10071007                return false;
     
    10141014
    10151015        // Append to Memcached value
    1016         if ( $byKey ) {
     1016        if ( $by_key ) {
    10171017            $result = $this->m->appendByKey( $server_key, $derived_key, $value );
    10181018        } else {
     
    10651065     * @param   int         $expiration     The expiration time, defaults to 0.
    10661066     * @param   string      $server_key     The key identifying the server to store the value on.
    1067      * @param   bool        $byKey          True to store in internal cache by key; false to not store by key
     1067     * @param   bool        $by_key         True to store in internal cache by key; false to not store by key
    10681068     * @return  bool                        Returns TRUE on success or FALSE on failure.
    10691069     */
    1070     public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) {
     1070    public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
    10711071        $derived_key = $this->buildKey( $key, $group );
    10721072        $expiration  = $this->sanitize_expiration( $expiration );
     
    10771077         * operation is treated as a normal "add" for no_mc_groups.
    10781078         */
    1079         if ( in_array( $group, $this->no_mc_groups ) ) {
     1079        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    10801080            $this->add_to_internal_cache( $derived_key, $value );
    10811081            return true;
     
    10831083
    10841084        // Save to Memcached
    1085         if ( $byKey ) {
     1085        if ( $by_key ) {
    10861086            $result = $this->m->casByKey( $cas_token, $server_key, $derived_key, $value, $expiration );
    10871087        } else {
     
    11311131
    11321132        // Decrement values in no_mc_groups
    1133         if ( in_array( $group, $this->no_mc_groups ) ) {
     1133        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    11341134
    11351135            // Only decrement if the key already exists and value is 0 or greater (mimics memcached behavior)
     
    11921192     * @param   int         $time       The amount of time the server will wait to delete the item in seconds.
    11931193     * @param   string      $server_key The key identifying the server to store the value on.
    1194      * @param   bool        $byKey      True to store in internal cache by key; false to not store by key
     1194     * @param   bool        $by_key     True to store in internal cache by key; false to not store by key
    11951195     * @return  bool                    Returns TRUE on success or FALSE on failure.
    11961196     */
    1197     public function delete( $key, $group = 'default', $time = 0, $server_key = '', $byKey = false ) {
     1197    public function delete( $key, $group = 'default', $time = 0, $server_key = '', $by_key = false ) {
    11981198        $derived_key = $this->buildKey( $key, $group );
    11991199
    12001200        // Remove from no_mc_groups array
    1201         if ( in_array( $group, $this->no_mc_groups ) ) {
     1201        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    12021202            if ( isset( $this->cache[ $derived_key ] ) ) {
    12031203                unset( $this->cache[ $derived_key ] );
     
    12071207        }
    12081208
    1209         if ( $byKey ) {
     1209        if ( $by_key ) {
    12101210            $result = $this->m->deleteByKey( $server_key, $derived_key, $time );
    12111211        } else {
     
    13001300     * @param   null|bool       $found      Variable passed by reference to determine if the value was found or not.
    13011301     * @param   string          $server_key The key identifying the server to store the value on.
    1302      * @param   bool            $byKey      True to store in internal cache by key; false to not store by key
     1302     * @param   bool            $by_key     True to store in internal cache by key; false to not store by key
    13031303     * @param   null|callable   $cache_cb   Read-through caching callback.
    13041304     * @param   null|float      $cas_token  The variable to store the CAS token in.
    13051305     * @return  bool|mixed                  Cached object value.
    13061306     */
    1307     public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $byKey = false, $cache_cb = null, &$cas_token = null ) {
     1307    public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $by_key = false, $cache_cb = null, &$cas_token = null ) {
    13081308        $derived_key = $this->buildKey( $key, $group );
    13091309
     
    13121312
    13131313        // If either $cache_db, or $cas_token is set, must hit Memcached and bypass runtime cache
    1314         if ( func_num_args() > 6 && ! in_array( $group, $this->no_mc_groups ) ) {
    1315             if ( $byKey ) {
     1314        if ( func_num_args() > 6 && ! in_array( $group, $this->no_mc_groups, true ) ) {
     1315            if ( $by_key ) {
    13161316                $value = $this->m->getByKey( $server_key, $derived_key, $cache_cb, $cas_token );
    13171317            } else {
     
    13221322                $found = true;
    13231323                return is_object( $this->cache[ $derived_key ] ) ? clone $this->cache[ $derived_key ] : $this->cache[ $derived_key ];
    1324             } elseif ( in_array( $group, $this->no_mc_groups ) ) {
     1324            } elseif ( in_array( $group, $this->no_mc_groups, true ) ) {
    13251325                return false;
    13261326            } else {
    1327                 if ( $byKey ) {
     1327                if ( $by_key ) {
    13281328                    $value = $this->m->getByKey( $server_key, $derived_key );
    13291329                } else {
     
    14651465
    14661466            // If order should be preserved, reorder now
    1467             if ( ! empty( $need_to_get ) && $flags === Memcached::GET_PRESERVE_ORDER ) {
     1467            if ( ! empty( $need_to_get ) && Memcached::GET_PRESERVE_ORDER === $flags ) {
    14681468                $ordered_values = array();
    14691469
     
    16041604
    16051605        // Increment values in no_mc_groups
    1606         if ( in_array( $group, $this->no_mc_groups ) ) {
     1606        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    16071607
    16081608            // Only increment if the key already exists and the number is currently 0 or greater (mimics memcached behavior)
     
    16691669     * @param   string    $group        The group value prepended to the $key.
    16701670     * @param   string    $server_key   The key identifying the server to store the value on.
    1671      * @param   bool      $byKey        True to store in internal cache by key; false to not store by key
     1671     * @param   bool      $by_key       True to store in internal cache by key; false to not store by key
    16721672     * @return  bool                    Returns TRUE on success or FALSE on failure.
    16731673     */
    1674     public function prepend( $key, $value, $group = 'default', $server_key = '', $byKey = false ) {
     1674    public function prepend( $key, $value, $group = 'default', $server_key = '', $by_key = false ) {
    16751675        if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) {
    16761676            return false;
     
    16801680
    16811681        // If group is a non-Memcached group, prepend to runtime cache value, not Memcached
    1682         if ( in_array( $group, $this->no_mc_groups ) ) {
     1682        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    16831683            if ( ! isset( $this->cache[ $derived_key ] ) ) {
    16841684                return false;
     
    16911691
    16921692        // Append to Memcached value
    1693         if ( $byKey ) {
     1693        if ( $by_key ) {
    16941694            $result = $this->m->prependByKey( $server_key, $derived_key, $value );
    16951695        } else {
     
    17411741     * @param   mixed       $value          The value to store.
    17421742     * @param   string      $group          The group value appended to the $key.
    1743      * @param   bool        $byKey          True to store in internal cache by key; false to not store by key
     1743     * @param   bool        $by_key         True to store in internal cache by key; false to not store by key
    17441744     * @param   int         $expiration     The expiration time, defaults to 0.
    17451745     * @return  bool                        Returns TRUE on success or FALSE on failure.
    17461746     */
    1747     public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) {
     1747    public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
    17481748        $derived_key = $this->buildKey( $key, $group );
    17491749        $expiration  = $this->sanitize_expiration( $expiration );
    17501750
    17511751        // If group is a non-Memcached group, save to runtime cache, not Memcached
    1752         if ( in_array( $group, $this->no_mc_groups ) ) {
     1752        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    17531753
    17541754            // Replace won't save unless the key already exists; mimic this behavior here
     
    17621762
    17631763        // Save to Memcached
    1764         if ( $byKey ) {
     1764        if ( $by_key ) {
    17651765            $result = $this->m->replaceByKey( $server_key, $derived_key, $value, $expiration );
    17661766        } else {
     
    18071807     * @param   int         $expiration The expiration time, defaults to 0.
    18081808     * @param   string      $server_key The key identifying the server to store the value on.
    1809      * @param   bool        $byKey      True to store in internal cache by key; false to not store by key
     1809     * @param   bool        $by_key     True to store in internal cache by key; false to not store by key
    18101810     * @return  bool                    Returns TRUE on success or FALSE on failure.
    18111811     */
    1812     public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $byKey = false ) {
     1812    public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
    18131813        $derived_key = $this->buildKey( $key, $group );
    18141814        $expiration  = $this->sanitize_expiration( $expiration );
    18151815
    18161816        // If group is a non-Memcached group, save to runtime cache, not Memcached
    1817         if ( in_array( $group, $this->no_mc_groups ) ) {
     1817        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    18181818            $this->add_to_internal_cache( $derived_key, $value );
    18191819            return true;
     
    18211821
    18221822        // Save to Memcached
    1823         if ( $byKey ) {
     1823        if ( $by_key ) {
    18241824            $result = $this->m->setByKey( $server_key, $derived_key, $value, $expiration );
    18251825        } else {
     
    18681868     * @param   int             $expiration     The expiration time, defaults to 0.
    18691869     * @param   string          $server_key     The key identifying the server to store the value on.
    1870      * @param   bool            $byKey          True to store in internal cache by key; false to not store by key
     1870     * @param   bool            $by_key         True to store in internal cache by key; false to not store by key
    18711871     * @return  bool                            Returns TRUE on success or FALSE on failure.
    18721872     */
    1873     public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $byKey = false ) {
     1873    public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
    18741874        // Build final keys and replace $items keys with the new keys
    18751875        $derived_keys  = $this->buildKeys( array_keys( $items ), $groups );
     
    18841884
    18851885            // If group is a non-Memcached group, save to runtime cache, not Memcached
    1886             if ( in_array( $key_pieces[1], $this->no_mc_groups ) ) {
     1886            if ( in_array( $key_pieces[1], $this->no_mc_groups, true ) ) {
    18871887                $this->add_to_internal_cache( $derived_key, $value );
    18881888                unset( $derived_items[ $derived_key ] );
     
    18911891
    18921892        // Save to memcached
    1893         if ( $byKey ) {
     1893        if ( $by_key ) {
    18941894            $result = $this->m->setMultiByKey( $server_key, $derived_items, $expiration );
    18951895        } else {
     
    19541954        }
    19551955
    1956         if ( false !== array_search( $group, $this->global_groups ) ) {
     1956        if ( false !== array_search( $group, $this->global_groups, true ) ) {
    19571957            $prefix = $this->global_prefix;
    19581958        } else {
     
    19921992
    19931993        // If we have equal numbers of keys and groups, merge $keys[n] and $group[n]
    1994         if ( count( $keys ) == count( $groups ) ) {
     1994        if ( count( $keys ) === count( $groups ) ) {
    19951995            for ( $i = 0; $i < count( $keys ); $i++ ) {
    19961996                $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] );
     
    20022002                if ( isset( $groups[ $i ] ) ) {
    20032003                    $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] );
    2004                 } elseif ( count( $groups ) == 1 ) {
     2004                } elseif ( count( $groups ) === 1 ) {
    20052005                    $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[0] );
    20062006                } else {
     
    20472047
    20482048        // Combine the values based on direction of the "pend"
    2049         if ( 'pre' == $direction ) {
     2049        if ( 'pre' === $direction ) {
    20502050            $combined = $pended . $original;
    20512051        } else {
     
    20812081    public function contains_no_mc_group( $groups ) {
    20822082        if ( is_scalar( $groups ) ) {
    2083             return in_array( $groups, $this->no_mc_groups );
     2083            return in_array( $groups, $this->no_mc_groups, true );
    20842084        }
    20852085
     
    20892089
    20902090        foreach ( $groups as $group ) {
    2091             if ( in_array( $group, $this->no_mc_groups ) ) {
     2091            if ( in_array( $group, $this->no_mc_groups, true ) ) {
    20922092                return true;
    20932093            }
Note: See TracChangeset for help on using the changeset viewer.