Skip to content

Commit 3e5b969

Browse files
authored
Merge pull request #103 from jrfnl/feature/cs-fixes-7
PHPCS: fix up the code base [7] - assignments in conditions
2 parents d9b54ef + babbfbf commit 3e5b969

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/Search_Replace_Command.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ public function __invoke( $args, $assoc_args ) {
172172
$this->recurse_objects = \WP_CLI\Utils\get_flag_value( $assoc_args, 'recurse-objects', true );
173173
$this->verbose = \WP_CLI\Utils\get_flag_value( $assoc_args, 'verbose' );
174174
$this->format = \WP_CLI\Utils\get_flag_value( $assoc_args, 'format' );
175+
$this->regex = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex', false );
175176

176-
if ( ( $this->regex = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex', false ) ) ) {
177+
if ( null !== $this->regex ) {
177178
$default_regex_delimiter = false;
178179
$this->regex_flags = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-flags', false );
179180
$this->regex_delimiter = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-delimiter', '' );
@@ -183,7 +184,8 @@ public function __invoke( $args, $assoc_args ) {
183184
}
184185
}
185186

186-
if ( null !== ( $regex_limit = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-limit' ) ) ) {
187+
$regex_limit = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-limit' );
188+
if ( null !== $regex_limit ) {
187189
if ( ! preg_match( '/^(?:[0-9]+|-1)$/', $regex_limit ) || 0 === (int) $regex_limit ) {
188190
WP_CLI::error( '`--regex-limit` expects a non-zero positive integer or -1.' );
189191
}
@@ -218,7 +220,8 @@ public function __invoke( $args, $assoc_args ) {
218220
exit;
219221
}
220222

221-
if ( null !== ( $export = \WP_CLI\Utils\get_flag_value( $assoc_args, 'export' ) ) ) {
223+
$export = \WP_CLI\Utils\get_flag_value( $assoc_args, 'export' );
224+
if ( null !== $export ) {
222225
if ( $this->dry_run ) {
223226
WP_CLI::error( 'You cannot supply --dry-run and --export at the same time.' );
224227
}
@@ -239,7 +242,8 @@ public function __invoke( $args, $assoc_args ) {
239242
$php_only = true;
240243
}
241244

242-
if ( null !== ( $log = \WP_CLI\Utils\get_flag_value( $assoc_args, 'log' ) ) ) {
245+
$log = \WP_CLI\Utils\get_flag_value( $assoc_args, 'log' );
246+
if ( null !== $log ) {
243247
if ( true === $log || '-' === $log ) {
244248
$this->log_handle = STDOUT;
245249
} else {
@@ -250,13 +254,18 @@ public function __invoke( $args, $assoc_args ) {
250254
}
251255
}
252256
if ( $this->log_handle ) {
253-
if ( null !== ( $before_context = \WP_CLI\Utils\get_flag_value( $assoc_args, 'before_context' ) ) && preg_match( '/^[0-9]+$/', $before_context ) ) {
257+
$before_context = \WP_CLI\Utils\get_flag_value( $assoc_args, 'before_context' );
258+
if ( null !== $before_context && preg_match( '/^[0-9]+$/', $before_context ) ) {
254259
$this->log_before_context = (int) $before_context;
255260
}
256-
if ( null !== ( $after_context = \WP_CLI\Utils\get_flag_value( $assoc_args, 'after_context' ) ) && preg_match( '/^[0-9]+$/', $after_context ) ) {
261+
262+
$after_context = \WP_CLI\Utils\get_flag_value( $assoc_args, 'after_context' );
263+
if ( null !== $after_context && preg_match( '/^[0-9]+$/', $after_context ) ) {
257264
$this->log_after_context = (int) $after_context;
258265
}
259-
if ( false !== ( $log_prefixes = getenv( 'WP_CLI_SEARCH_REPLACE_LOG_PREFIXES' ) ) && preg_match( '/^([^,]*),([^,]*)$/', $log_prefixes, $matches ) ) {
266+
267+
$log_prefixes = getenv( 'WP_CLI_SEARCH_REPLACE_LOG_PREFIXES' );
268+
if ( false !== $log_prefixes && preg_match( '/^([^,]*),([^,]*)$/', $log_prefixes, $matches ) ) {
260269
$this->log_prefixes = array( $matches[1], $matches[2] );
261270
}
262271

@@ -273,7 +282,9 @@ public function __invoke( $args, $assoc_args ) {
273282
'log_new' => '',
274283
);
275284
}
276-
if ( false !== ( $log_colors = getenv( 'WP_CLI_SEARCH_REPLACE_LOG_COLORS' ) ) && preg_match( '/^([^,]*),([^,]*),([^,]*)$/', $log_colors, $matches ) ) {
285+
286+
$log_colors = getenv( 'WP_CLI_SEARCH_REPLACE_LOG_COLORS' );
287+
if ( false !== $log_colors && preg_match( '/^([^,]*),([^,]*),([^,]*)$/', $log_colors, $matches ) ) {
277288
$default_log_colors = array(
278289
'log_table_column_id' => $matches[1],
279290
'log_old' => $matches[2],
@@ -629,7 +640,8 @@ private static function get_columns( $table ) {
629640
$text_columns = array();
630641
$all_columns = array();
631642
$suppress_errors = $wpdb->suppress_errors();
632-
if ( ( $results = $wpdb->get_results( "DESCRIBE $table_sql" ) ) ) {
643+
$results = $wpdb->get_results( "DESCRIBE $table_sql" );
644+
if ( ! empty( $results ) ) {
633645
foreach ( $results as $col ) {
634646
if ( 'PRI' === $col->Key ) {
635647
$primary_keys[] = $col->Field;
@@ -732,7 +744,8 @@ private function get_colors( $assoc_args, $colors ) {
732744
$color_codes_regex = '/^(?:%[' . $color_codes . '])*$/';
733745

734746
foreach ( array_keys( $colors ) as $color_col ) {
735-
if ( null !== ( $col_color_flag = \WP_CLI\Utils\get_flag_value( $assoc_args, $color_col . '_color' ) ) ) {
747+
$col_color_flag = \WP_CLI\Utils\get_flag_value( $assoc_args, $color_col . '_color' );
748+
if ( null !== $col_color_flag ) {
736749
if ( ! preg_match( $color_codes_regex, $col_color_flag, $matches ) ) {
737750
WP_CLI::warning( "Unrecognized percent color code '$col_color_flag' for '{$color_col}_color'." );
738751
} else {
@@ -763,7 +776,9 @@ private function log_sql_diff( $col, $primary_keys, $table, $old, $new ) {
763776
} else {
764777
$primary_keys_sql = '';
765778
}
766-
if ( ! ( $results = $wpdb->get_results( $wpdb->prepare( "SELECT {$primary_keys_sql}`$col` FROM `$table` WHERE `$col` LIKE BINARY %s", '%' . self::esc_like( $old ) . '%' ), ARRAY_N ) ) ) {
779+
780+
$results = $wpdb->get_results( $wpdb->prepare( "SELECT {$primary_keys_sql}`$col` FROM `$table` WHERE `$col` LIKE BINARY %s", '%' . self::esc_like( $old ) . '%' ), ARRAY_N );
781+
if ( empty( $results ) ) {
767782
return 0;
768783
}
769784

src/WP_CLI/SearchReplacer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ private function _run( $data, $serialised, $recursion_level = 0, $visited_data =
8282
}
8383
}
8484

85-
if ( is_string( $data ) && false !== ( $unserialized = @unserialize( $data ) ) ) {
85+
$unserialized = @unserialize( $data );
86+
if ( is_string( $data ) && false !== $unserialized ) {
8687
$data = $this->_run( $unserialized, true, $recursion_level + 1 );
8788
} elseif ( is_array( $data ) ) {
8889
$keys = array_keys( $data );

0 commit comments

Comments
 (0)