Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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/wp-db.php

    r42228 r42343  
    242242         * @var array
    243243         */
    244         var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta',
    245                 'terms', 'term_taxonomy', 'term_relationships', 'termmeta', 'commentmeta' );
     244        var $tables = array(
     245                'posts',
     246                'comments',
     247                'links',
     248                'options',
     249                'postmeta',
     250                'terms',
     251                'term_taxonomy',
     252                'term_relationships',
     253                'termmeta',
     254                'commentmeta',
     255        );
    246256
    247257        /**
    … …  
    272282         * @var array
    273283         */
    274         var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta',
    275                 'sitecategories', 'registration_log', 'blog_versions' );
     284        var $ms_global_tables = array(
     285                'blogs',
     286                'signups',
     287                'site',
     288                'sitemeta',
     289                'sitecategories',
     290                'registration_log',
     291                'blog_versions',
     292        );
    276293
    277294        /**
    … …  
    529546         * @var array
    530547         */
    531         protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY',
    532                 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' );
     548        protected $incompatible_modes = array(
     549                'NO_ZERO_DATE',
     550                'ONLY_FULL_GROUP_BY',
     551                'STRICT_TRANS_TABLES',
     552                'STRICT_ALL_TABLES',
     553                'TRADITIONAL',
     554        );
    533555
    534556        /**
    … …  
    568590                register_shutdown_function( array( $this, '__destruct' ) );
    569591
    570                 if ( WP_DEBUG && WP_DEBUG_DISPLAY )
     592                if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
    571593                        $this->show_errors();
     594                }
    572595
    573596                /* Use ext/mysqli if it exists and:
    … …  
    587610                }
    588611
    589                 $this->dbuser = $dbuser;
     612                $this->dbuser     = $dbuser;
    590613                $this->dbpassword = $dbpassword;
    591                 $this->dbname = $dbname;
    592                 $this->dbhost = $dbhost;
     614                $this->dbname     = $dbname;
     615                $this->dbhost     = $dbhost;
    593616
    594617                // wp-config.php creation will manually connect when ready.
    … …  
    620643         */
    621644        public function __get( $name ) {
    622                 if ( 'col_info' === $name )
     645                if ( 'col_info' === $name ) {
    623646                        $this->load_col_info();
     647                }
    624648
    625649                return $this->$name;
    … …  
    640664                        'check_current_query',
    641665                );
    642                 if (  in_array( $name, $protected_members, true ) ) {
     666                if ( in_array( $name, $protected_members, true ) ) {
    643667                        return;
    644668                }
    … …  
    679703                $collate = '';
    680704
    681                 if ( function_exists('is_multisite') && is_multisite() ) {
     705                if ( function_exists( 'is_multisite' ) && is_multisite() ) {
    682706                        $charset = 'utf8';
    683707                        if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) {
    … …  
    752776         */
    753777        public function set_charset( $dbh, $charset = null, $collate = null ) {
    754                 if ( ! isset( $charset ) )
     778                if ( ! isset( $charset ) ) {
    755779                        $charset = $this->charset;
    756                 if ( ! isset( $collate ) )
     780                }
     781                if ( ! isset( $collate ) ) {
    757782                        $collate = $this->collate;
     783                }
    758784                if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) {
    759785                        $set_charset_succeeded = true;
    … …  
    766792                                if ( $set_charset_succeeded ) {
    767793                                        $query = $this->prepare( 'SET NAMES %s', $charset );
    768                                         if ( ! empty( $collate ) )
     794                                        if ( ! empty( $collate ) ) {
    769795                                                $query .= $this->prepare( ' COLLATE %s', $collate );
     796                                        }
    770797                                        mysqli_query( $dbh, $query );
    771798                                }
    … …  
    776803                                if ( $set_charset_succeeded ) {
    777804                                        $query = $this->prepare( 'SET NAMES %s', $charset );
    778                                         if ( ! empty( $collate ) )
     805                                        if ( ! empty( $collate ) ) {
    779806                                                $query .= $this->prepare( ' COLLATE %s', $collate );
     807                                        }
    780808                                        mysql_query( $query, $dbh );
    781809                                }
    … …  
    860888        public function set_prefix( $prefix, $set_table_names = true ) {
    861889
    862                 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
    863                         return new WP_Error('invalid_db_prefix', 'Invalid database prefix' );
     890                if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {
     891                        return new WP_Error( 'invalid_db_prefix', 'Invalid database prefix' );
     892                }
    864893
    865894                $old_prefix = is_multisite() ? '' : $prefix;
    866895
    867                 if ( isset( $this->base_prefix ) )
     896                if ( isset( $this->base_prefix ) ) {
    868897                        $old_prefix = $this->base_prefix;
     898                }
    869899
    870900                $this->base_prefix = $prefix;
    871901
    872902                if ( $set_table_names ) {
    873                         foreach ( $this->tables( 'global' ) as $table => $prefixed_table )
     903                        foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) {
    874904                                $this->$table = $prefixed_table;
    875 
    876                         if ( is_multisite() && empty( $this->blogid ) )
     905                        }
     906
     907                        if ( is_multisite() && empty( $this->blogid ) ) {
    877908                                return $old_prefix;
     909                        }
    878910
    879911                        $this->prefix = $this->get_blog_prefix();
    880912
    881                         foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
     913                        foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
    882914                                $this->$table = $prefixed_table;
    883 
    884                         foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
     915                        }
     916
     917                        foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
    885918                                $this->$table = $prefixed_table;
     919                        }
    886920                }
    887921                return $old_prefix;
    … …  
    907941                $this->prefix = $this->get_blog_prefix();
    908942
    909                 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
     943                foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
    910944                        $this->$table = $prefixed_table;
    911 
    912                 foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
     945                }
     946
     947                foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
    913948                        $this->$table = $prefixed_table;
     949                }
    914950
    915951                return $old_blog_id;
    … …  
    925961        public function get_blog_prefix( $blog_id = null ) {
    926962                if ( is_multisite() ) {
    927                         if ( null === $blog_id )
     963                        if ( null === $blog_id ) {
    928964                                $blog_id = $this->blogid;
     965                        }
    929966                        $blog_id = (int) $blog_id;
    930                         if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) )
     967                        if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) {
    931968                                return $this->base_prefix;
    932                         else
     969                        } else {
    933970                                return $this->base_prefix . $blog_id . '_';
     971                        }
    934972                } else {
    935973                        return $this->base_prefix;
    … …  
    9661004        public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
    9671005                switch ( $scope ) {
    968                         case 'all' :
     1006                        case 'all':
    9691007                                $tables = array_merge( $this->global_tables, $this->tables );
    970                                 if ( is_multisite() )
     1008                                if ( is_multisite() ) {
    9711009                                        $tables = array_merge( $tables, $this->ms_global_tables );
     1010                                }
    9721011                                break;
    973                         case 'blog' :
     1012                        case 'blog':
    9741013                                $tables = $this->tables;
    9751014                                break;
    976                         case 'global' :
     1015                        case 'global':
    9771016                                $tables = $this->global_tables;
    978                                 if ( is_multisite() )
     1017                                if ( is_multisite() ) {
    9791018                                        $tables = array_merge( $tables, $this->ms_global_tables );
     1019                                }
    9801020                                break;
    981                         case 'ms_global' :
     1021                        case 'ms_global':
    9821022                                $tables = $this->ms_global_tables;
    9831023                                break;
    984                         case 'old' :
     1024                        case 'old':
    9851025                                $tables = $this->old_tables;
    9861026                                break;
    987                         default :
     1027                        default:
    9881028                                return array();
    9891029                }
    9901030
    9911031                if ( $prefix ) {
    992                         if ( ! $blog_id )
     1032                        if ( ! $blog_id ) {
    9931033                                $blog_id = $this->blogid;
    994                         $blog_prefix = $this->get_blog_prefix( $blog_id );
    995                         $base_prefix = $this->base_prefix;
     1034                        }
     1035                        $blog_prefix   = $this->get_blog_prefix( $blog_id );
     1036                        $base_prefix   = $this->base_prefix;
    9961037                        $global_tables = array_merge( $this->global_tables, $this->ms_global_tables );
    9971038                        foreach ( $tables as $k => $table ) {
    998                                 if ( in_array( $table, $global_tables ) )
     1039                                if ( in_array( $table, $global_tables ) ) {
    9991040                                        $tables[ $table ] = $base_prefix . $table;
    1000                                 else
     1041                                } else {
    10011042                                        $tables[ $table ] = $blog_prefix . $table;
     1043                                }
    10021044                                unset( $tables[ $k ] );
    10031045                        }
    10041046
    1005                         if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) )
     1047                        if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) {
    10061048                                $tables['users'] = CUSTOM_USER_TABLE;
    1007 
    1008                         if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) )
     1049                        }
     1050
     1051                        if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) {
    10091052                                $tables['usermeta'] = CUSTOM_USER_META_TABLE;
     1053                        }
    10101054                }
    10111055
    … …  
    10251069         */
    10261070        public function select( $db, $dbh = null ) {
    1027                 if ( is_null($dbh) )
     1071                if ( is_null( $dbh ) ) {
    10281072                        $dbh = $this->dbh;
     1073                }
    10291074
    10301075                if ( $this->use_mysqli ) {
    … …  
    10521097                                        /* translators: 1: database user, 2: database name */
    10531098                                        __( 'Does the user %1$s have permission to use the %2$s database?' ),
    1054                                         '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES )  . '</code>',
     1099                                        '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES ) . '</code>',
    10551100                                        '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>'
    10561101                                ) . "</li>\n";
    … …  
    10601105                                        __( 'On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?' ),
    10611106                                        htmlspecialchars( $db, ENT_QUOTES )
    1062                                 ). "</li>\n";
     1107                                ) . "</li>\n";
    10631108
    10641109                                $message .= "</ul>\n";
    … …  
    10891134         */
    10901135        function _weak_escape( $string ) {
    1091                 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) )
     1136                if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) {
    10921137                        _deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' );
     1138                }
    10931139                return addslashes( $string );
    10941140        }
    … …  
    11381184                        foreach ( $data as $k => $v ) {
    11391185                                if ( is_array( $v ) ) {
    1140                                         $data[$k] = $this->_escape( $v );
     1186                                        $data[ $k ] = $this->_escape( $v );
    11411187                                } else {
    1142                                         $data[$k] = $this->_real_escape( $v );
     1188                                        $data[ $k ] = $this->_real_escape( $v );
    11431189                                }
    11441190                        }
    … …  
    11641210         */
    11651211        public function escape( $data ) {
    1166                 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) )
     1212                if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) {
    11671213                        _deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' );
     1214                }
    11681215                if ( is_array( $data ) ) {
    11691216                        foreach ( $data as $k => $v ) {
    1170                                 if ( is_array( $v ) )
    1171                                         $data[$k] = $this->escape( $v, 'recursive' );
    1172                                 else
    1173                                         $data[$k] = $this->_weak_escape( $v, 'internal' );
     1217                                if ( is_array( $v ) ) {
     1218                                        $data[ $k ] = $this->escape( $v, 'recursive' );
     1219                                } else {
     1220                                        $data[ $k ] = $this->_weak_escape( $v, 'internal' );
     1221                                }
    11741222                        }
    11751223                } else {
    … …  
    11901238         */
    11911239        public function escape_by_ref( &$string ) {
    1192                 if ( ! is_float( $string ) )
     1240                if ( ! is_float( $string ) ) {
    11931241                        $string = $this->_real_escape( $string );
     1242                }
    11941243        }
    11951244
    … …  
    12451294                if ( is_array( $args[0] ) && count( $args ) == 1 ) {
    12461295                        $passed_as_array = true;
    1247                         $args = $args[0];
     1296                        $args            = $args[0];
    12481297                }
    12491298
    … …  
    12771326                $query = preg_replace( '/(?<!%)%s/', "'%s'", $query ); // Quote the strings, avoiding escaped strings like %%s.
    12781327
    1279                 $query = preg_replace( "/(?<!%)(%($allowed_format)?f)/" , '%\\2F', $query ); // Force floats to be locale unaware.
     1328                $query = preg_replace( "/(?<!%)(%($allowed_format)?f)/", '%\\2F', $query ); // Force floats to be locale unaware.
    12801329
    12811330                $query = preg_replace( "/%(?:%|$|(?!($allowed_format)?[sdF]))/", '%%\\1', $query ); // Escape any unescaped percents.
    … …  
    12971346                                 */
    12981347                                wp_load_translations_early();
    1299                                 _doing_it_wrong( 'wpdb::prepare',
     1348                                _doing_it_wrong(
     1349                                        'wpdb::prepare',
    13001350                                        /* translators: 1: number of placeholders, 2: number of arguments passed */
    1301                                         sprintf( __( 'The query does not contain the correct number of placeholders (%1$d) for the number of arguments passed (%2$d).' ),
     1351                                        sprintf(
     1352                                                __( 'The query does not contain the correct number of placeholders (%1$d) for the number of arguments passed (%2$d).' ),
    13021353                                                $placeholders,
    1303                                                 count( $args ) ),
     1354                                                count( $args )
     1355                                        ),
    13041356                                        '4.8.3'
    13051357                                );
    … …  
    13521404                global $EZSQL_ERROR;
    13531405
    1354                 if ( !$str ) {
     1406                if ( ! $str ) {
    13551407                        if ( $this->use_mysqli ) {
    13561408                                $str = mysqli_error( $this->dbh );
    … …  
    13591411                        }
    13601412                }
    1361                 $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str );
    1362 
    1363                 if ( $this->suppress_errors )
     1413                $EZSQL_ERROR[] = array(
     1414                        'query'     => $this->last_query,
     1415                        'error_str' => $str,
     1416                );
     1417
     1418                if ( $this->suppress_errors ) {
    13641419                        return false;
     1420                }
    13651421
    13661422                wp_load_translations_early();
    … …  
    13771433
    13781434                // Are we showing errors?
    1379                 if ( ! $this->show_errors )
     1435                if ( ! $this->show_errors ) {
    13801436                        return false;
     1437                }
    13811438
    13821439                // If there is an error then take note of it
    … …  
    14231480         */
    14241481        public function show_errors( $show = true ) {
    1425                 $errors = $this->show_errors;
     1482                $errors            = $this->show_errors;
    14261483                $this->show_errors = $show;
    14271484                return $errors;
    … …  
    14391496         */
    14401497        public function hide_errors() {
    1441                 $show = $this->show_errors;
     1498                $show              = $this->show_errors;
    14421499                $this->show_errors = false;
    14431500                return $show;
    … …  
    14561513         */
    14571514        public function suppress_errors( $suppress = true ) {
    1458                 $errors = $this->suppress_errors;
     1515                $errors                = $this->suppress_errors;
    14591516                $this->suppress_errors = (bool) $suppress;
    14601517                return $errors;
    … …  
    14671524         */
    14681525        public function flush() {
    1469                 $this->last_result = array();
    1470                 $this->col_info    = null;
    1471                 $this->last_query  = null;
     1526                $this->last_result   = array();
     1527                $this->col_info      = null;
     1528                $this->last_query    = null;
    14721529                $this->rows_affected = $this->num_rows = 0;
    1473                 $this->last_error  = '';
     1530                $this->last_error    = '';
    14741531
    14751532                if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
    … …  
    14781535
    14791536                        // Sanity check before using the handle
    1480                         if ( empty( $this->dbh ) || !( $this->dbh instanceof mysqli ) ) {
     1537                        if ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) {
    14811538                                return;
    14821539                        }
    … …  
    15101567                 * $new_link parameter exists for mysqli_* functions.
    15111568                 */
    1512                 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
     1569                $new_link     = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
    15131570                $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
    15141571
    … …  
    15461603                                /*
    15471604                                 * It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
    1548                                 *  - We haven't previously connected, and
    1549                                 *  - WP_USE_EXT_MYSQL isn't set to false, and
    1550                                 *  - ext/mysql is loaded.
    1551                                 */
     1605                                  *  - We haven't previously connected, and
     1606                                  *  - WP_USE_EXT_MYSQL isn't set to false, and
     1607                                  *  - ext/mysql is loaded.
     1608                                  */
    15521609                                $attempt_fallback = true;
    15531610
    … …  
    16481705                if ( $socket_pos !== false ) {
    16491706                        $socket = substr( $host, $socket_pos + 1 );
    1650                         $host = substr( $host, 0, $socket_pos );
     1707                        $host   = substr( $host, 0, $socket_pos );
    16511708                }
    16521709
    … …  
    16621719
    16631720                $matches = array();
    1664                 $result = preg_match( $pattern, $host, $matches );
     1721                $result  = preg_match( $pattern, $host, $matches );
    16651722
    16661723                if ( 1 !== $result ) {
    … …  
    18661923                if ( $this->last_error ) {
    18671924                        // Clear insert_id on a subsequent failed insert.
    1868                         if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) )
     1925                        if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
    18691926                                $this->insert_id = 0;
     1927                        }
    18701928
    18711929                        $this->print_error();
    … …  
    18951953                        if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
    18961954                                while ( $row = mysqli_fetch_object( $this->result ) ) {
    1897                                         $this->last_result[$num_rows] = $row;
     1955                                        $this->last_result[ $num_rows ] = $row;
    18981956                                        $num_rows++;
    18991957                                }
    19001958                        } elseif ( is_resource( $this->result ) ) {
    19011959                                while ( $row = mysql_fetch_object( $this->result ) ) {
    1902                                         $this->last_result[$num_rows] = $row;
     1960                                        $this->last_result[ $num_rows ] = $row;
    19031961                                        $num_rows++;
    19041962                                }
    … …  
    21622220
    21632221                        $conditions[] = "`$field` = " . $value['format'];
    2164                         $values[] = $value['value'];
    2165                 }
    2166 
    2167                 $fields = implode( ', ', $fields );
     2222                        $values[]     = $value['value'];
     2223                }
     2224
     2225                $fields     = implode( ', ', $fields );
    21682226                $conditions = implode( ' AND ', $conditions );
    21692227
    … …  
    22142272
    22152273                        $conditions[] = "`$field` = " . $value['format'];
    2216                         $values[] = $value['value'];
     2274                        $values[]     = $value['value'];
    22172275                }
    22182276
    … …  
    23892447
    23902448                // Extract var out of cached results based x,y vals
    2391                 if ( !empty( $this->last_result[$y] ) ) {
    2392                         $values = array_values( get_object_vars( $this->last_result[$y] ) );
     2449                if ( ! empty( $this->last_result[ $y ] ) ) {
     2450                        $values = array_values( get_object_vars( $this->last_result[ $y ] ) );
    23932451                }
    23942452
    23952453                // If there is a value return it else return null
    2396                 return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null;
     2454                return ( isset( $values[ $x ] ) && $values[ $x ] !== '' ) ? $values[ $x ] : null;
    23972455        }
    23982456
    … …  
    24232481                }
    24242482
    2425                 if ( !isset( $this->last_result[$y] ) )
     2483                if ( ! isset( $this->last_result[ $y ] ) ) {
    24262484                        return null;
     2485                }
    24272486
    24282487                if ( $output == OBJECT ) {
    2429                         return $this->last_result[$y] ? $this->last_result[$y] : null;
     2488                        return $this->last_result[ $y ] ? $this->last_result[ $y ] : null;
    24302489                } elseif ( $output == ARRAY_A ) {
    2431                         return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null;
     2490                        return $this->last_result[ $y ] ? get_object_vars( $this->last_result[ $y ] ) : null;
    24322491                } elseif ( $output == ARRAY_N ) {
    2433                         return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null;
     2492                        return $this->last_result[ $y ] ? array_values( get_object_vars( $this->last_result[ $y ] ) ) : null;
    24342493                } elseif ( strtoupper( $output ) === OBJECT ) {
    24352494                        // Back compat for OBJECT being previously case insensitive.
    2436                         return $this->last_result[$y] ? $this->last_result[$y] : null;
     2495                        return $this->last_result[ $y ] ? $this->last_result[ $y ] : null;
    24372496                } else {
    2438                         $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" );
     2497                        $this->print_error( ' $db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N' );
    24392498                }
    24402499        }
    … …  
    24532512         * @return array Database query result. Array indexed from 0 by SQL result row number.
    24542513         */
    2455         public function get_col( $query = null , $x = 0 ) {
     2514        public function get_col( $query = null, $x = 0 ) {
    24562515                if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
    24572516                        $this->check_current_query = false;
    … …  
    24652524                // Extract the column values
    24662525                for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
    2467                         $new_array[$i] = $this->get_var( null, $x, $i );
     2526                        $new_array[ $i ] = $this->get_var( null, $x, $i );
    24682527                }
    24692528                return $new_array;
    … …  
    25072566                        foreach ( $this->last_result as $row ) {
    25082567                                $var_by_ref = get_object_vars( $row );
    2509                                 $key = array_shift( $var_by_ref );
    2510                                 if ( ! isset( $new_array[ $key ] ) )
     2568                                $key        = array_shift( $var_by_ref );
     2569                                if ( ! isset( $new_array[ $key ] ) ) {
    25112570                                        $new_array[ $key ] = $row;
     2571                                }
    25122572                        }
    25132573                        return $new_array;
    … …  
    25672627
    25682628                $table_parts = explode( '.', $table );
    2569                 $table = '`' . implode( '`.`', $table_parts ) . '`';
    2570                 $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" );
     2629                $table       = '`' . implode( '`.`', $table_parts ) . '`';
     2630                $results     = $this->get_results( "SHOW FULL COLUMNS FROM $table" );
    25712631                if ( ! $results ) {
    25722632                        return new WP_Error( 'wpdb_get_table_charset_failure' );
    … …  
    26442704         */
    26452705        public function get_col_charset( $table, $column ) {
    2646                 $tablekey = strtolower( $table );
     2706                $tablekey  = strtolower( $table );
    26472707                $columnkey = strtolower( $column );
    26482708
    … …  
    27092769         */
    27102770        public function get_col_length( $table, $column ) {
    2711                 $tablekey = strtolower( $table );
     2771                $tablekey  = strtolower( $table );
    27122772                $columnkey = strtolower( $column );
    27132773
    … …  
    27382798                }
    27392799
    2740                 switch( $type ) {
     2800                switch ( $type ) {
    27412801                        case 'char':
    27422802                        case 'varchar':
    … …  
    28392899
    28402900                $this->checking_collation = true;
    2841                 $collation = $this->get_table_charset( $table );
     2901                $collation                = $this->get_table_charset( $table );
    28422902                $this->checking_collation = false;
    28432903
    … …  
    28862946
    28872947                        if ( is_array( $value['length'] ) ) {
    2888                                 $length = $value['length']['length'];
     2948                                $length                  = $value['length']['length'];
    28892949                                $truncate_by_byte_length = 'byte' === $value['length']['type'];
    28902950                        } else {
    … …  
    29152975                        ) {
    29162976                                $truncate_by_byte_length = true;
    2917                                 $needs_validation = false;
     2977                                $needs_validation        = false;
    29182978                        }
    29192979
    … …  
    29493009                                }
    29503010
    2951                                 $regex .= '){1,40}                          # ...one or more times
     3011                                $regex         .= '){1,40}                          # ...one or more times
    29523012                                        )
    29533013                                        | .                                  # anything else
    29543014                                        /x';
    29553015                                $value['value'] = preg_replace( $regex, '$1', $value['value'] );
    2956 
    29573016
    29583017                                if ( false !== $length && mb_strlen( $value['value'], 'UTF-8' ) > $length ) {
    … …  
    29903049
    29913050                                        if ( is_array( $value['length'] ) ) {
    2992                                                 $length = sprintf( '%.0f', $value['length']['length'] );
     3051                                                $length          = sprintf( '%.0f', $value['length']['length'] );
    29933052                                                $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), $length ) USING $connection_charset )", $value['value'] );
    2994                                         } else if ( 'binary' !== $charset ) {
     3053                                        } elseif ( 'binary' !== $charset ) {
    29953054                                                // If we don't have a length, there's no need to convert binary - it will always return the same result.
    29963055                                                $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] );
    … …  
    30113070
    30123071                        $this->check_current_query = false;
    3013                         $row = $this->get_row( "SELECT " . implode( ', ', $sql ), ARRAY_A );
     3072                        $row                       = $this->get_row( 'SELECT ' . implode( ', ', $sql ), ARRAY_A );
    30143073                        if ( ! $row ) {
    30153074                                return new WP_Error( 'wpdb_strip_invalid_text_failure' );
    … …  
    30173076
    30183077                        foreach ( array_keys( $data ) as $column ) {
    3019                                 if ( isset( $row["x_$column"] ) ) {
    3020                                         $data[ $column ]['value'] = $row["x_$column"];
     3078                                if ( isset( $row[ "x_$column" ] ) ) {
     3079                                        $data[ $column ]['value'] = $row[ "x_$column" ];
    30213080                                }
    30223081                        }
    … …  
    31003159                                'charset' => $charset,
    31013160                                'length'  => $this->get_col_length( $table, $column ),
    3102                         )
     3161                        ),
    31033162                );
    31043163
    … …  
    31303189
    31313190                // Quickly match most common queries.
    3132                 if ( preg_match( '/^\s*(?:'
     3191                if ( preg_match(
     3192                        '/^\s*(?:'
    31333193                                . 'SELECT.*?\s+FROM'
    31343194                                . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?'
    … …  
    31363196                                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    31373197                                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:.+?FROM)?'
    3138                                 . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     3198                        . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe
     3199                ) ) {
    31393200                        return str_replace( '`', '', $maybe[1] );
    31403201                }
    … …  
    31553216
    31563217                // Big pattern for the rest of the table-related queries.
    3157                 if ( preg_match( '/^\s*(?:'
     3218                if ( preg_match(
     3219                        '/^\s*(?:'
    31583220                                . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM'
    31593221                                . '|DESCRIBE|DESC|EXPLAIN|HANDLER'
    … …  
    31693231                                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    31703232                                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    3171                                 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     3233                        . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe
     3234                ) ) {
    31723235                        return str_replace( '`', '', $maybe[1] );
    31733236                }
    … …  
    31803243         *
    31813244         * @since 3.5.0
    3182          *
    31833245         */
    31843246        protected function load_col_info() {
    3185                 if ( $this->col_info )
     3247                if ( $this->col_info ) {
    31863248                        return;
     3249                }
    31873250
    31883251                if ( $this->use_mysqli ) {
    … …  
    32133276                if ( $this->col_info ) {
    32143277                        if ( $col_offset == -1 ) {
    3215                                 $i = 0;
     3278                                $i         = 0;
    32163279                                $new_array = array();
    32173280                                foreach ( (array) $this->col_info as $col ) {
    3218                                         $new_array[$i] = $col->{$info_type};
     3281                                        $new_array[ $i ] = $col->{$info_type};
    32193282                                        $i++;
    32203283                                }
    32213284                                return $new_array;
    32223285                        } else {
    3223                                 return $this->col_info[$col_offset]->{$info_type};
     3286                                return $this->col_info[ $col_offset ]->{$info_type};
    32243287                        }
    32253288                }
    … …  
    32613324         */
    32623325        public function bail( $message, $error_code = '500' ) {
    3263                 if ( !$this->show_errors ) {
     3326                if ( ! $this->show_errors ) {
    32643327                        if ( class_exists( 'WP_Error', false ) ) {
    3265                                 $this->error = new WP_Error($error_code, $message);
     3328                                $this->error = new WP_Error( $error_code, $message );
    32663329                        } else {
    32673330                                $this->error = $message;
    … …  
    32693332                        return false;
    32703333                }
    3271                 wp_die($message);
     3334                wp_die( $message );
    32723335        }
    32733336
    … …  
    32933356
    32943357                if ( $closed ) {
    3295                         $this->dbh = null;
    3296                         $this->ready = false;
     3358                        $this->dbh           = null;
     3359                        $this->ready         = false;
    32973360                        $this->has_connected = false;
    32983361                }
    … …  
    33143377                global $wp_version, $required_mysql_version;
    33153378                // Make sure the server has the required MySQL version
    3316                 if ( version_compare($this->db_version(), $required_mysql_version, '<') ) {
     3379                if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) {
    33173380                        /* translators: 1: WordPress version number, 2: Minimum required MySQL version number */
    3318                         return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ));
     3381                        return new WP_Error( 'database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ) );
    33193382                }
    33203383        }
    … …  
    33473410                $charset_collate = '';
    33483411
    3349                 if ( ! empty( $this->charset ) )
     3412                if ( ! empty( $this->charset ) ) {
    33503413                        $charset_collate = "DEFAULT CHARACTER SET $this->charset";
    3351                 if ( ! empty( $this->collate ) )
     3414                }
     3415                if ( ! empty( $this->collate ) ) {
    33523416                        $charset_collate .= " COLLATE $this->collate";
     3417                }
    33533418
    33543419                return $charset_collate;
    … …  
    33733438
    33743439                switch ( strtolower( $db_cap ) ) {
    3375                         case 'collation' :    // @since 2.5.0
    3376                         case 'group_concat' : // @since 2.7.0
    3377                         case 'subqueries' :   // @since 2.7.0
     3440                        case 'collation':    // @since 2.5.0
     3441                        case 'group_concat': // @since 2.7.0
     3442                        case 'subqueries':   // @since 2.7.0
    33783443                                return version_compare( $version, '4.1', '>=' );
    3379                         case 'set_charset' :
     3444                        case 'set_charset':
    33803445                                return version_compare( $version, '5.0.7', '>=' );
    3381                         case 'utf8mb4' :      // @since 4.1.0
     3446                        case 'utf8mb4':      // @since 4.1.0
    33823447                                if ( version_compare( $version, '5.5.3', '<' ) ) {
    33833448                                        return false;
    … …  
    33993464                                        return version_compare( $client_version, '5.5.3', '>=' );
    34003465                                }
    3401                         case 'utf8mb4_520' : // @since 4.6.0
     3466                        case 'utf8mb4_520': // @since 4.6.0
    34023467                                return version_compare( $version, '5.6', '>=' );
    34033468                }
Note: See TracChangeset for help on using the changeset viewer.