Skip to content

Commit 37e7679

Browse files
committed
fix: optimize format handling in checksum verification errors
1 parent 805292f commit 37e7679

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/Checksum_Core_Command.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ class Checksum_Core_Command extends Checksum_Base_Command {
105105
* @when before_wp_load
106106
*/
107107
public function __invoke( $args, $assoc_args ) {
108-
$wp_version = '';
109-
$locale = '';
108+
$wp_version = '';
109+
$locale = '';
110+
$has_formatter = isset( $assoc_args['format'] );
110111

111112
if ( ! empty( $assoc_args['version'] ) ) {
112113
$wp_version = $assoc_args['version'];
@@ -160,7 +161,7 @@ public function __invoke( $args, $assoc_args ) {
160161
}
161162

162163
if ( ! file_exists( ABSPATH . $file ) ) {
163-
if ( isset( $assoc_args['format'] ) ) {
164+
if ( $has_formatter ) {
164165
$this->add_error( $file, "File doesn't exist" );
165166
} else {
166167
WP_CLI::warning( "File doesn't exist: {$file}" );
@@ -171,7 +172,7 @@ public function __invoke( $args, $assoc_args ) {
171172

172173
$md5_file = md5_file( ABSPATH . $file );
173174
if ( $md5_file !== $checksum ) {
174-
if ( isset( $assoc_args['format'] ) ) {
175+
if ( $has_formatter ) {
175176
$this->add_error( $file, "File doesn't verify against checksum" );
176177
} else {
177178
WP_CLI::warning( "File doesn't verify against checksum: {$file}" );
@@ -189,15 +190,15 @@ public function __invoke( $args, $assoc_args ) {
189190
if ( in_array( $additional_file, $this->exclude_files, true ) ) {
190191
continue;
191192
}
192-
if ( isset( $assoc_args['format'] ) ) {
193+
if ( $has_formatter ) {
193194
$this->add_error( $additional_file, 'File should not exist' );
194195
} else {
195196
WP_CLI::warning( "File should not exist: {$additional_file}" );
196197
}
197198
}
198199
}
199200

200-
if ( ! empty( $this->errors ) && isset( $assoc_args['format'] ) ) {
201+
if ( ! empty( $this->errors ) && $has_formatter ) {
201202
$formatter = new Formatter(
202203
$assoc_args,
203204
array( 'file', 'message' )

0 commit comments

Comments
 (0)