Skip to content

Commit 7d3ddb8

Browse files
committed
DRY: Extract condition
1 parent 0e84308 commit 7d3ddb8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/DB_Command.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,10 @@ public function query( $args, $assoc_args ) {
506506
if ( isset( $assoc_args['execute'] ) ) {
507507
$assoc_args['execute'] = $this->get_sql_mode_query( $assoc_args ) . $assoc_args['execute'];
508508
}
509-
510-
// Check if the query is an UPDATE or DELETE.
511-
if ( isset( $assoc_args['execute'] ) && preg_match( '/\b(UPDATE|DELETE|INSERT)\b/i', $assoc_args['execute'] ) ) {
509+
510+
$is_update_or_delete = isset( $assoc_args['execute'] ) && preg_match( '/\b(UPDATE|DELETE|INSERT)\b/i', $assoc_args['execute'] );
511+
512+
if ( $is_update_or_delete ) {
512513
// Append `SELECT ROW_COUNT()` to the query.
513514
$assoc_args['execute'] .= '; SELECT ROW_COUNT();';
514515
}
@@ -521,7 +522,7 @@ public function query( $args, $assoc_args ) {
521522
}
522523

523524
// For UPDATE/DELETE queries, parse the output to get the number of rows affected.
524-
if ( isset( $assoc_args['execute'] ) && preg_match( '/\b(UPDATE|DELETE|INSERT)\b/i', $assoc_args['execute'] ) ) {
525+
if ( $is_update_or_delete ) {
525526
$output_lines = explode( "\n", trim( $stdout ) );
526527
$affected_rows = (int) trim( end( $output_lines ) );
527528
WP_CLI::success( "Query succeeded. Rows affected: {$affected_rows}" );

0 commit comments

Comments
 (0)