Skip to content

Commit 2c9ba2e

Browse files
committed
Refactoring
1 parent fce4c28 commit 2c9ba2e

File tree

2 files changed

+28
-13
lines changed
  • app/code/Magento/Cms/Model/Wysiwyg/Images
  • dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images

2 files changed

+28
-13
lines changed

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -631,17 +631,7 @@ public function resizeFile($source, $keepRatio = true)
631631

632632
$image->keepAspectRatio($keepRatio);
633633

634-
list($imageWidth, $imageHeight) = @getimagesize($source);
635-
636-
if ($imageWidth && $imageHeight) {
637-
$configWidth = $this->_resizeParameters['width'];
638-
$configHeight = $this->_resizeParameters['height'];
639-
$imageWidth = $configWidth > $imageWidth ? $imageWidth : $configWidth;
640-
$imageHeight = $configHeight > $imageHeight ? $imageHeight : $configHeight;
641-
} else {
642-
$imageWidth = $this->_resizeParameters['width'];
643-
$imageHeight = $this->_resizeParameters['height'];
644-
}
634+
list($imageWidth, $imageHeight) = $this->getResizedParams($source);
645635

646636
$image->resize($imageWidth, $imageHeight);
647637
$dest = $targetDir . '/' . $this->ioFile->getPathInfo($source)['basename'];
@@ -652,6 +642,29 @@ public function resizeFile($source, $keepRatio = true)
652642
return false;
653643
}
654644

645+
/**
646+
* Return width height for the image resizing.
647+
*
648+
* @param string $source
649+
*/
650+
private function getResizedParams(string $source): array
651+
{
652+
$configWidth = $this->_resizeParameters['width'];
653+
$configHeight = $this->_resizeParameters['height'];
654+
655+
//phpcs:ignore Generic.PHP.NoSilencedErrors
656+
list($imageWidth, $imageHeight) = @getimagesize($source);
657+
658+
if ($imageWidth && $imageHeight) {
659+
$imageWidth = $configWidth > $imageWidth ? $imageWidth : $configWidth;
660+
$imageHeight = $configHeight > $imageHeight ? $imageHeight : $configHeight;
661+
} else {
662+
return [$configWidth, $configHeight];
663+
}
664+
665+
return [$imageWidth, $imageHeight];
666+
}
667+
655668
/**
656669
* Resize images on the fly in controller action
657670
*

dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public function testUploadFile(): void
167167
public function testUploadFileWithExcludedDirPath(): void
168168
{
169169
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
170-
$this->expectExceptionMessage('We can\'t upload the file to current folder right now. Please try another folder.');
170+
$this->expectExceptionMessage(
171+
'We can\'t upload the file to current folder right now. Please try another folder.'
172+
);
171173

172174
$fileName = 'magento_small_image.jpg';
173175
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
@@ -335,7 +337,7 @@ public function getThumbnailsSizes(): array
335337
'width' => 1024,
336338
'height' => 768,
337339
],
338-
true
340+
true
339341
],
340342
[
341343
[

0 commit comments

Comments
 (0)