From 49ef52c657de7ac1e50010ce3f6b0cdc40c02dc7 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 1 Sep 2023 15:08:38 +0200 Subject: [PATCH] Update to WPCS v3 (#184) * Update to wp-cli-tests v4 (which requires WPCS v3) * Fix all autofixable CS issues * Fix PHPCS issue --------- Co-authored-by: Daniel Bachhuber --- composer.json | 2 +- media-command.php | 2 +- src/Media_Command.php | 50 +++++++++++++++++++++---------------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 2a0ce7d1b..ec0ee90ac 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require-dev": { "wp-cli/entity-command": "^1.3 || ^2", "wp-cli/extension-command": "^2.0", - "wp-cli/wp-cli-tests": "^3.1" + "wp-cli/wp-cli-tests": "^4" }, "config": { "process-timeout": 7200, diff --git a/media-command.php b/media-command.php index f5c4e74da..626c7cee5 100644 --- a/media-command.php +++ b/media-command.php @@ -4,7 +4,7 @@ return; } -$wpcli_media_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; +$wpcli_media_autoloader = __DIR__ . '/vendor/autoload.php'; if ( file_exists( $wpcli_media_autoloader ) ) { require_once $wpcli_media_autoloader; } diff --git a/src/Media_Command.php b/src/Media_Command.php index 3fc9f254c..969457600 100644 --- a/src/Media_Command.php +++ b/src/Media_Command.php @@ -155,7 +155,7 @@ public function regenerate( $args, $assoc_args = array() ) { $errors = 0; $skips = 0; foreach ( $images->posts as $post ) { - $number++; + ++$number; if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) { Utils\wp_clear_object_cache(); } @@ -286,7 +286,7 @@ public function import( $args, $assoc_args = array() ) { $successes = 0; $errors = 0; foreach ( $args as $file ) { - $number++; + ++$number; if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) { Utils\wp_clear_object_cache(); } @@ -299,7 +299,7 @@ public function import( $args, $assoc_args = array() ) { if ( empty( $is_file_remote ) ) { if ( ! file_exists( $file ) ) { WP_CLI::warning( "Unable to import file '$file'. Reason: File doesn't exist." ); - $errors++; + ++$errors; continue; } if ( Utils\get_flag_value( $assoc_args, 'skip-copy' ) ) { @@ -322,7 +322,7 @@ public function import( $args, $assoc_args = array() ) { implode( ', ', $tempfile->get_error_messages() ) ) ); - $errors++; + ++$errors; continue; } $name = strtok( Utils\basename( $file ), '?' ); @@ -383,7 +383,7 @@ public function import( $args, $assoc_args = array() ) { implode( ', ', $success->get_error_messages() ) ) ); - $errors++; + ++$errors; continue; } wp_update_attachment_metadata( $success, wp_generate_attachment_metadata( $success, $file ) ); @@ -398,7 +398,7 @@ public function import( $args, $assoc_args = array() ) { implode( ', ', $success->get_error_messages() ) ) ); - $errors++; + ++$errors; continue; } } @@ -438,7 +438,7 @@ public function import( $args, $assoc_args = array() ) { ) ); } - $successes++; + ++$successes; } // Report the result of the operation @@ -507,7 +507,7 @@ public function image_size( $args, $assoc_args ) { usort( $sizes, - function( $a, $b ) { + function ( $a, $b ) { if ( $a['width'] === $b['width'] ) { return 0; } @@ -588,7 +588,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_ if ( false === $fullsizepath || ! file_exists( $fullsizepath ) ) { WP_CLI::warning( "Can't find $att_desc." ); - $errors++; + ++$errors; return; } @@ -600,13 +600,13 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_ if ( $skip_it ) { WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc." ); - $skips++; + ++$skips; return; } if ( $only_missing && ! $needs_regeneration ) { WP_CLI::log( "$progress No $thumbnail_desc regeneration needed for $att_desc." ); - $successes++; + ++$successes; return; } @@ -614,7 +614,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_ if ( is_wp_error( $metadata ) ) { WP_CLI::warning( sprintf( '%s (ID %d)', $metadata->get_error_message(), $id ) ); WP_CLI::log( "$progress Couldn't regenerate thumbnails for $att_desc." ); - $errors++; + ++$errors; return; } @@ -622,7 +622,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_ if ( empty( $metadata ) && ! ( $is_pdf && $image_size ) ) { WP_CLI::warning( sprintf( 'No metadata. (ID %d)', $id ) ); WP_CLI::log( "$progress Couldn't regenerate thumbnails for $att_desc." ); - $errors++; + ++$errors; return; } @@ -630,7 +630,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_ if ( 1 === count( $metadata ) && array_key_exists( 'filesize', $metadata ) && ! ( $is_pdf && $image_size ) ) { WP_CLI::warning( sprintf( 'Read error while retrieving metadata. (ID %d)', $id ) ); WP_CLI::log( "$progress Couldn't regenerate thumbnails for $att_desc." ); - $errors++; + ++$errors; return; } @@ -645,7 +645,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_ WP_CLI::log( "$progress Regenerated thumbnails for $att_desc." ); } - $successes++; + ++$successes; } private function remove_old_images( $metadata, $fullsizepath, $image_size ) { @@ -841,13 +841,11 @@ private function get_intermediate_sizes( $is_pdf, $metadata, $att_id ) { if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) { $sizes[ $s ]['crop'] = (bool) $_wp_additional_image_sizes[ $s ]['crop']; - } else { // Force PDF thumbnails to be soft crops. - if ( $is_pdf && 'thumbnail' === $s ) { - $sizes[ $s ]['crop'] = false; - } else { - $sizes[ $s ]['crop'] = (bool) get_option( "{$s}_crop" ); - } + } elseif ( $is_pdf && 'thumbnail' === $s ) { + $sizes[ $s ]['crop'] = false; + } else { + $sizes[ $s ]['crop'] = (bool) get_option( "{$s}_crop" ); } } @@ -1055,7 +1053,7 @@ public function fix_orientation( $args, $assoc_args ) { $successes = 0; $errors = 0; foreach ( $images->posts as $post ) { - $number++; + ++$number; if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) { Utils\wp_clear_object_cache(); } @@ -1096,7 +1094,7 @@ private function process_orientation_fix( $id, $progress, &$successes, &$errors, if ( false === $full_size_path || ! file_exists( $full_size_path ) ) { WP_CLI::warning( "Can't find {$att_desc}." ); - $errors++; + ++$errors; return; } @@ -1108,14 +1106,14 @@ private function process_orientation_fix( $id, $progress, &$successes, &$errors, if ( ! $dry_run ) { WP_CLI::log( "{$progress} Fixing orientation for {$att_desc}." ); if ( false !== $this->flip_rotate_image( $id, $metadata, $image_meta, $full_size_path ) ) { - $successes++; + ++$successes; } else { - $errors++; + ++$errors; WP_CLI::log( "Couldn't fix orientation for {$att_desc}." ); } } else { WP_CLI::log( "{$progress} {$att_desc} will be affected." ); - $successes++; + ++$successes; } } else { WP_CLI::log( "{$progress} No orientation fix required for {$att_desc}." );