[wp-trac] [WordPress Trac] #56982: Empty ELSE statement
WordPress Trac
noreply at wordpress.org
Thu Dec 15 23:45:06 UTC 2022
#56982: Empty ELSE statement
-----------------------------+-------------------------------
Reporter: krunal265 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Upgrade/Install | Version: 1.5
Severity: trivial | Resolution:
Keywords: dev-feedback | Focuses: coding-standards
-----------------------------+-------------------------------
Changes (by costdev):
* keywords: => dev-feedback
* severity: major => trivial
Comment:
I don't have strong feelings, although I do wonder whether the comment
adds anything beneficial to the reader's understanding of the code.
We could change the initial comment:
Create a tablename index for an array ($cqueries) of queries.
to
Create a tablename index for an array ($cqueries) of recognised query
types.
In addition, if we're going to remove the comment and `else`, we could
also use `continue` to help separate each case and help a little with
readability by not having a wall of `if`/`elseif`.
-----
**Current**
{{{#!php
<?php
// Create a tablename index for an array ($cqueries) of queries.
foreach ( $queries as $qry ) {
if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
$cqueries[ trim( $matches[1], '`' ) ] = $qry;
$for_update[ $matches[1] ] = 'Created table ' .
$matches[1];
} elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches
) ) {
array_unshift( $cqueries, $qry );
} elseif ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) )
{
$iqueries[] = $qry;
} elseif ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
$iqueries[] = $qry;
} else {
// Unrecognized query type.
}
}
}}}
**Proposed**
{{{#!php
<?php
// Create a tablename index for an array ($cqueries) of recognised query
types.
foreach ( $queries as $qry ) {
if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
$cqueries[ trim( $matches[1], '`' ) ] = $qry;
$for_update[ $matches[1] ] = 'Created table ' .
$matches[1];
continue;
}
if ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) {
array_unshift( $cqueries, $qry );
continue;
}
if ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) {
$iqueries[] = $qry;
continue;
}
if ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
$iqueries[] = $qry;
}
}
}}}
-----
Thoughts?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56982#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list