Make WordPress Core

Ticket #43761: 43761-fix-coding-standards.patch

File 43761-fix-coding-standards.patch, 6.2 KB (added by jipmoors, 7 years ago)
  • src/wp-admin/install-helper.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    5656                                return true;
    5757                        }
    5858                }
    59                 // Didn't find it, so try to create it.
    60                 $wpdb->query( $create_ddl );
     59                /*
     60                 * Didn't find it, so try to create it.
     61                 *
     62                 * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because there are no
     63                 * variables applicable here.
     64                 */
     65                $wpdb->query( $create_ddl ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
    6166
    6267                // We cannot directly tell that whether this succeeded!
    6368                foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) {
     
    8489         */
    8590        function maybe_add_column( $table_name, $column_name, $create_ddl ) {
    8691                global $wpdb;
    87                 foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
    8892
    89                         if ( $column == $column_name ) {
     93                /*
     94                 * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because this statement cannot be prepared,
     95                 * it fetches the columns for a table name, which cannot be quoted.
     96                 */
     97                foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
     98                        if ( $column === $column_name ) {
    9099                                return true;
    91100                        }
    92101                }
    93102
    94                 // Didn't find it, so try to create it.
    95                 $wpdb->query( $create_ddl );
     103                /*
     104                 * Didn't find it, so try to create it.
     105                 *
     106                 * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because there
     107                 * are no variables applicable for this query.
     108                 */
     109                $wpdb->query( $create_ddl ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
    96110
    97                 // We cannot directly tell that whether this succeeded!
    98                 foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
    99                         if ( $column == $column_name ) {
     111                /*
     112                 * We cannot directly tell that whether this succeeded!
     113                 *
     114                 * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because this statement cannot be prepared,
     115                 * it fetches the columns for a table name, which cannot be quoted.
     116                 */
     117                foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
     118                        if ( $column === $column_name ) {
    100119                                return true;
    101120                        }
    102121                }
     
    118137 */
    119138function maybe_drop_column( $table_name, $column_name, $drop_ddl ) {
    120139        global $wpdb;
    121         foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
    122                 if ( $column == $column_name ) {
    123140
    124                         // Found it, so try to drop it.
    125                         $wpdb->query( $drop_ddl );
     141        /*
     142         * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because this statement cannot be prepared,
     143         * it fetches the columns for a table name, which cannot be quoted.
     144         */
     145        foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
     146                if ( $column === $column_name ) {
    126147
    127                         // We cannot directly tell that whether this succeeded!
    128                         foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
    129                                 if ( $column == $column_name ) {
     148                        /*
     149                         * Found it, so try to drop it.
     150                         *
     151                         * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because there are no attributes
     152                         * relevant for this query.
     153                         */
     154                        $wpdb->query( $drop_ddl ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
     155
     156                        /*
     157                         * We cannot directly tell that whether this succeeded!
     158                         *
     159                         * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because this statement cannot be prepared,
     160                         * it fetches the columns for a table name, which cannot be quoted.
     161                         */
     162                        foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
     163                                if ( $column === $column_name ) {
    130164                                        return false;
    131165                                }
    132166                        }
     
    167201 */
    168202function check_column( $table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null ) {
    169203        global $wpdb;
     204
     205        /*
     206         * The phpcs ignore (WordPress.WP.PreparedSQL.NotPrepared) has been added because this statement cannot be prepared,
     207         * it fetches the columns for a table name, which cannot be quoted.
     208         */
     209        $results = $wpdb->get_results( "DESC $table_name" ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
    170210        $diffs   = 0;
    171         $results = $wpdb->get_results( "DESC $table_name" );
    172211
    173212        foreach ( $results as $row ) {
    174213
    175                 if ( $row->Field == $col_name ) {
     214                // The results are named via SQL standards, thus the capital letter cannot be resolved otherwise.
     215                $result_field   = $row->Field; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
     216                $result_type    = $row->Type; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
     217                $result_null    = $row->Null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
     218                $result_key     = $row->Key; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
     219                $result_default = $row->Default; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
     220                $result_extra   = $row->Extra; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
     221
     222                if ( $result_field == $col_name ) {
    176223
    177224                        // Got our column, check the params.
    178                         if ( ( $col_type != null ) && ( $row->Type != $col_type ) ) {
     225                        if ( ( null !== $col_type ) && ( $result_type != $col_type ) ) {
    179226                                ++$diffs;
    180227                        }
    181                         if ( ( $is_null != null ) && ( $row->Null != $is_null ) ) {
     228                        if ( ( null !== $is_null ) && ( $result_null != $is_null ) ) {
    182229                                ++$diffs;
    183230                        }
    184                         if ( ( $key != null ) && ( $row->Key != $key ) ) {
     231                        if ( ( null !== $key ) && ( $result_key != $key ) ) {
    185232                                ++$diffs;
    186233                        }
    187                         if ( ( $default != null ) && ( $row->Default != $default ) ) {
     234                        if ( ( null !== $default ) && ( $result_default != $default ) ) {
    188235                                ++$diffs;
    189236                        }
    190                         if ( ( $extra != null ) && ( $row->Extra != $extra ) ) {
     237                        if ( ( null !== $extra ) && ( $result_extra != $extra ) ) {
    191238                                ++$diffs;
    192239                        }
    193240                        if ( $diffs > 0 ) {