Skip to content

Commit d88fae4

Browse files
committed
MAGETWO-90927: Refactor conditional to avoid complexity by checking existence of array and matching existing image count to current image count
1 parent 080420a commit d88fae4

File tree

1 file changed

+5
-7
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product

1 file changed

+5
-7
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public function execute()
194194
*/
195195
private function handleImageRemoveError($postData, $productId)
196196
{
197-
198197
if (isset($postData['product']['media_gallery']['images'])) {
199198
$removedImagesAmount = 0;
200199
foreach ($postData['product']['media_gallery']['images'] as $image) {
@@ -205,12 +204,11 @@ private function handleImageRemoveError($postData, $productId)
205204
if ($removedImagesAmount) {
206205
$expectedImagesAmount = count($postData['product']['media_gallery']['images']) - $removedImagesAmount;
207206
$product = $this->productRepository->getById($productId);
208-
if (is_array($product->getMediaGallery('images'))) {
209-
if ($expectedImagesAmount != count($product->getMediaGallery('images'))) {
210-
$this->messageManager->addNoticeMessage(
211-
__('The image cannot be removed as it has been assigned to the other image role')
212-
);
213-
}
207+
$images = $product->getMediaGallery('images');
208+
if (is_array($images) && $expectedImagesAmount != count($images)) {
209+
$this->messageManager->addNoticeMessage(
210+
__('The image cannot be removed as it has been assigned to the other image role')
211+
);
214212
}
215213
}
216214
}

0 commit comments

Comments
 (0)