Coding Standards: Fix WPCS issues in wp-admin/install-helper.php.

This commit adds inline comments instructing PHPCS to ignore some lines for database queries. An explanation is provided with each instruction.

This resolves a few WPCS warnings along the lines of:
{{{
Use placeholders and $wpdb->prepare(); found interpolated variable $table_name at "DESC $table_name"
}}}

Follow-up to [236], [265], [5778].

Props jipmoors, costdev, jrf, SergeyBiryukov.
Fixes #43761.
Built from https://develop.svn.wordpress.org/trunk@54858


git-svn-id: http://core.svn.wordpress.org/trunk@54410 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-11-19 15:42:16 +00:00
parent 513a8dc17f
commit f299e3c83a
2 changed files with 11 additions and 2 deletions

View File

@ -59,6 +59,7 @@ if ( ! function_exists( 'maybe_create_table' ) ) :
}
// Didn't find it, so try to create it.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.
$wpdb->query( $create_ddl );
// We cannot directly tell that whether this succeeded!
@ -88,6 +89,7 @@ if ( ! function_exists( 'maybe_add_column' ) ) :
function maybe_add_column( $table_name, $column_name, $create_ddl ) {
global $wpdb;
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names.
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
return true;
@ -95,9 +97,11 @@ if ( ! function_exists( 'maybe_add_column' ) ) :
}
// Didn't find it, so try to create it.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.
$wpdb->query( $create_ddl );
// We cannot directly tell that whether this succeeded!
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names.
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
return true;
@ -123,13 +127,16 @@ endif;
function maybe_drop_column( $table_name, $column_name, $drop_ddl ) {
global $wpdb;
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names.
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
// Found it, so try to drop it.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.
$wpdb->query( $drop_ddl );
// We cannot directly tell that whether this succeeded!
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names.
foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
if ( $column === $column_name ) {
return false;
@ -174,7 +181,9 @@ function maybe_drop_column( $table_name, $column_name, $drop_ddl ) {
function check_column( $table_name, $col_name, $col_type, $is_null = null, $key = null, $default_value = null, $extra = null ) {
global $wpdb;
$diffs = 0;
$diffs = 0;
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Cannot be prepared. Fetches columns for table names.
$results = $wpdb->get_results( "DESC $table_name" );
foreach ( $results as $row ) {

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-54857';
$wp_version = '6.2-alpha-54858';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.