From caddf7e3dc3f94579e40b833c62f648371b691bf Mon Sep 17 00:00:00 2001
From: Sergey Biryukov <sergeybiryukov.ru@gmail.com>
Date: Wed, 16 Aug 2023 14:05:20 +0000
Subject: [PATCH] Coding Standards: Use strict comparison in
 `wp-admin/includes/image-edit.php`.

Follow-up to [11911], [11965], [11984], [12155], [12163], [22094].

Props aristath, poena, afercia, SergeyBiryukov.
See #58831.
Built from https://develop.svn.wordpress.org/trunk@56400


git-svn-id: http://core.svn.wordpress.org/trunk@55912 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
 wp-admin/includes/image-edit.php | 52 +++++++++++++++++++++-----------
 wp-includes/version.php          |  2 +-
 2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php
index 72a6d07c01..ebc1a73a97 100644
--- a/wp-admin/includes/image-edit.php
+++ b/wp-admin/includes/image-edit.php
@@ -636,15 +636,18 @@ function image_edit_apply_changes( $image, $changes ) {
 			$obj->sel  = $obj->c;
 			unset( $obj->c );
 		}
+
 		$changes[ $key ] = $obj;
 	}
 
 	// Combine operations.
 	if ( count( $changes ) > 1 ) {
 		$filtered = array( $changes[0] );
+
 		for ( $i = 0, $j = 1, $c = count( $changes ); $j < $c; $j++ ) {
 			$combined = false;
-			if ( $filtered[ $i ]->type == $changes[ $j ]->type ) {
+
+			if ( $filtered[ $i ]->type === $changes[ $j ]->type ) {
 				switch ( $filtered[ $i ]->type ) {
 					case 'rotate':
 						$filtered[ $i ]->angle += $changes[ $j ]->angle;
@@ -656,10 +659,12 @@ function image_edit_apply_changes( $image, $changes ) {
 						break;
 				}
 			}
+
 			if ( ! $combined ) {
 				$filtered[ ++$i ] = $changes[ $j ];
 			}
 		}
+
 		$changes = $filtered;
 		unset( $filtered );
 	}
@@ -693,7 +698,7 @@ function image_edit_apply_changes( $image, $changes ) {
 	foreach ( $changes as $operation ) {
 		switch ( $operation->type ) {
 			case 'rotate':
-				if ( 0 != $operation->angle ) {
+				if ( 0 !== $operation->angle ) {
 					if ( $image instanceof WP_Image_Editor ) {
 						$image->rotate( $operation->angle );
 					} else {
@@ -702,11 +707,11 @@ function image_edit_apply_changes( $image, $changes ) {
 				}
 				break;
 			case 'flip':
-				if ( 0 != $operation->axis ) {
+				if ( 0 !== $operation->axis ) {
 					if ( $image instanceof WP_Image_Editor ) {
-						$image->flip( ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
+						$image->flip( ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 );
 					} else {
-						$image = _flip_image_resource( $image, ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 );
+						$image = _flip_image_resource( $image, ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 );
 					}
 				}
 				break;
@@ -801,9 +806,8 @@ function wp_restore_image( $post_id ) {
 	if ( isset( $backup_sizes['full-orig'] ) && is_array( $backup_sizes['full-orig'] ) ) {
 		$data = $backup_sizes['full-orig'];
 
-		if ( $parts['basename'] != $data['file'] ) {
+		if ( $parts['basename'] !== $data['file'] ) {
 			if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
-
 				// Delete only if it's an edited image.
 				if ( preg_match( '/-e[0-9]{13}\./', $parts['basename'] ) ) {
 					wp_delete_file( $file );
@@ -828,9 +832,9 @@ function wp_restore_image( $post_id ) {
 	foreach ( $default_sizes as $default_size ) {
 		if ( isset( $backup_sizes[ "$default_size-orig" ] ) ) {
 			$data = $backup_sizes[ "$default_size-orig" ];
-			if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] != $data['file'] ) {
-				if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
 
+			if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] !== $data['file'] ) {
+				if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
 					// Delete only if it's an edited image.
 					if ( preg_match( '/-e[0-9]{13}-/', $meta['sizes'][ $default_size ]['file'] ) ) {
 						$delete_file = path_join( $parts['dirname'], $meta['sizes'][ $default_size ]['file'] );
@@ -847,9 +851,9 @@ function wp_restore_image( $post_id ) {
 		}
 	}
 
-	if ( ! wp_update_attachment_metadata( $post_id, $meta ) ||
-		( $old_backup_sizes !== $backup_sizes && ! update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ) ) ) {
-
+	if ( ! wp_update_attachment_metadata( $post_id, $meta )
+		|| ( $old_backup_sizes !== $backup_sizes && ! update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ) )
+	) {
 		$msg->error = __( 'Cannot save image metadata.' );
 		return $msg;
 	}
@@ -858,6 +862,7 @@ function wp_restore_image( $post_id ) {
 		$msg->error = __( 'Image metadata is inconsistent.' );
 	} else {
 		$msg->msg = __( 'Image restored successfully.' );
+
 		if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
 			delete_post_meta( $post_id, '_wp_attachment_backup_sizes' );
 		}
@@ -886,6 +891,7 @@ function wp_save_image( $post_id ) {
 	$post    = get_post( $post_id );
 
 	$img = wp_get_image_editor( _load_image_to_edit_path( $post_id, 'full' ) );
+
 	if ( is_wp_error( $img ) ) {
 		$return->error = esc_js( __( 'Unable to create new image.' ) );
 		return $return;
@@ -955,8 +961,9 @@ function wp_save_image( $post_id ) {
 	$filename = pathinfo( $path, PATHINFO_FILENAME );
 	$suffix   = time() . rand( 100, 999 );
 
-	if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE &&
-		isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] != $basename ) {
+	if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE
+		&& isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] !== $basename
+	) {
 
 		if ( $edit_thumbnails_separately && 'thumbnail' === $target ) {
 			$new_path = "{$dirname}/{$filename}-temp.{$ext}";
@@ -969,6 +976,7 @@ function wp_save_image( $post_id ) {
 			$filename    .= "-e{$suffix}";
 			$new_filename = "{$filename}.{$ext}";
 			$new_path     = "{$dirname}/$new_filename";
+
 			if ( file_exists( $new_path ) ) {
 				$suffix++;
 			} else {
@@ -985,8 +993,11 @@ function wp_save_image( $post_id ) {
 
 	if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
 		$tag = false;
+
 		if ( isset( $backup_sizes['full-orig'] ) ) {
-			if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] !== $basename ) {
+			if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE )
+				&& $backup_sizes['full-orig']['file'] !== $basename
+			) {
 				$tag = "full-$suffix";
 			}
 		} else {
@@ -1000,6 +1011,7 @@ function wp_save_image( $post_id ) {
 				'file'   => $basename,
 			);
 		}
+
 		$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
 
 		$meta['file'] = _wp_relative_upload_path( $new_path );
@@ -1045,9 +1057,12 @@ function wp_save_image( $post_id ) {
 
 		foreach ( $sizes as $size ) {
 			$tag = false;
+
 			if ( isset( $meta['sizes'][ $size ] ) ) {
 				if ( isset( $backup_sizes[ "$size-orig" ] ) ) {
-					if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes[ "$size-orig" ]['file'] != $meta['sizes'][ $size ]['file'] ) {
+					if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE )
+						&& $backup_sizes[ "$size-orig" ]['file'] !== $meta['sizes'][ $size ]['file']
+					) {
 						$tag = "$size-$suffix";
 					}
 				} else {
@@ -1088,10 +1103,12 @@ function wp_save_image( $post_id ) {
 		if ( 'thumbnail' === $target || 'all' === $target || 'full' === $target ) {
 			// Check if it's an image edit from attachment edit screen.
 			if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' === $_REQUEST['context'] ) {
-				$thumb_url         = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true );
+				$thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true );
+
 				$return->thumbnail = $thumb_url[0];
 			} else {
 				$file_url = wp_get_attachment_url( $post_id );
+
 				if ( ! empty( $meta['sizes']['thumbnail'] ) ) {
 					$thumb             = $meta['sizes']['thumbnail'];
 					$return->thumbnail = path_join( dirname( $file_url ), $thumb['file'] );
@@ -1109,5 +1126,6 @@ function wp_save_image( $post_id ) {
 	}
 
 	$return->msg = esc_js( __( 'Image saved' ) );
+
 	return $return;
 }
diff --git a/wp-includes/version.php b/wp-includes/version.php
index aec4a419be..d19b3353c6 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '6.4-alpha-56399';
+$wp_version = '6.4-alpha-56400';
 
 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.