Skip to content

Commit 84b22c1

Browse files
fix static
1 parent 988f31b commit 84b22c1

File tree

1 file changed

+32
-49
lines changed

1 file changed

+32
-49
lines changed

app/code/Magento/Catalog/Model/ImageUploader.php

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,109 +5,102 @@
55
*/
66
namespace Magento\Catalog\Model;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Exception\LocalizedException;
810
use Magento\Framework\File\Uploader;
911
use Magento\Framework\App\ObjectManager;
1012
use Magento\Framework\File\Name;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Filesystem\Directory\WriteInterface;
15+
use Magento\MediaStorage\Helper\File\Storage\Database;
16+
use Magento\MediaStorage\Model\File\UploaderFactory;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
use Psr\Log\LoggerInterface;
1119

1220
/**
1321
* Catalog image uploader
1422
*/
1523
class ImageUploader
1624
{
1725
/**
18-
* Core file storage database
19-
*
20-
* @var \Magento\MediaStorage\Helper\File\Storage\Database
26+
* @var Database
2127
*/
2228
protected $coreFileStorageDatabase;
2329

2430
/**
25-
* Media directory object (writable).
26-
*
27-
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
31+
* @var WriteInterface
2832
*/
2933
protected $mediaDirectory;
3034

3135
/**
32-
* Uploader factory
33-
*
34-
* @var \Magento\MediaStorage\Model\File\UploaderFactory
36+
* @var UploaderFactory
3537
*/
3638
private $uploaderFactory;
3739

3840
/**
39-
* Store manager
40-
*
41-
* @var \Magento\Store\Model\StoreManagerInterface
41+
* @var StoreManagerInterface
4242
*/
4343
protected $storeManager;
4444

4545
/**
46-
* @var \Psr\Log\LoggerInterface
46+
* @var LoggerInterface
4747
*/
4848
protected $logger;
4949

5050
/**
51-
* Base tmp path
52-
*
5351
* @var string
5452
*/
5553
protected $baseTmpPath;
5654

5755
/**
58-
* Base path
59-
*
6056
* @var string
6157
*/
6258
protected $basePath;
6359

6460
/**
65-
* Allowed extensions
66-
*
6761
* @var string
6862
*/
6963
protected $allowedExtensions;
7064

7165
/**
72-
* List of allowed image mime types
73-
*
7466
* @var string[]
7567
*/
7668
private $allowedMimeTypes;
7769

7870
/**
79-
* @var \Magento\Framework\File\Name
71+
* @var Name
8072
*/
8173
private $fileNameLookup;
8274

8375
/**
8476
* ImageUploader constructor.
8577
*
86-
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase
87-
* @param \Magento\Framework\Filesystem $filesystem
88-
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
89-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
90-
* @param \Psr\Log\LoggerInterface $logger
78+
* @param Database $coreFileStorageDatabase
79+
* @param Filesystem $filesystem
80+
* @param UploaderFactory $uploaderFactory
81+
* @param StoreManagerInterface $storeManager
82+
* @param LoggerInterface $logger
9183
* @param string $baseTmpPath
9284
* @param string $basePath
9385
* @param string[] $allowedExtensions
9486
* @param string[] $allowedMimeTypes
9587
* @param Name|null $fileNameLookup
88+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9689
*/
9790
public function __construct(
98-
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
99-
\Magento\Framework\Filesystem $filesystem,
100-
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
101-
\Magento\Store\Model\StoreManagerInterface $storeManager,
102-
\Psr\Log\LoggerInterface $logger,
91+
Database $coreFileStorageDatabase,
92+
Filesystem $filesystem,
93+
UploaderFactory $uploaderFactory,
94+
StoreManagerInterface $storeManager,
95+
LoggerInterface $logger,
10396
$baseTmpPath,
10497
$basePath,
10598
$allowedExtensions,
10699
$allowedMimeTypes = [],
107100
Name $fileNameLookup = null
108101
) {
109102
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
110-
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
103+
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
111104
$this->uploaderFactory = $uploaderFactory;
112105
$this->storeManager = $storeManager;
113106
$this->logger = $logger;
@@ -122,7 +115,6 @@ public function __construct(
122115
* Set base tmp path
123116
*
124117
* @param string $baseTmpPath
125-
*
126118
* @return void
127119
*/
128120
public function setBaseTmpPath($baseTmpPath)
@@ -134,7 +126,6 @@ public function setBaseTmpPath($baseTmpPath)
134126
* Set base path
135127
*
136128
* @param string $basePath
137-
*
138129
* @return void
139130
*/
140131
public function setBasePath($basePath)
@@ -146,7 +137,6 @@ public function setBasePath($basePath)
146137
* Set allowed extensions
147138
*
148139
* @param string[] $allowedExtensions
149-
*
150140
* @return void
151141
*/
152142
public function setAllowedExtensions($allowedExtensions)
@@ -189,7 +179,6 @@ public function getAllowedExtensions()
189179
*
190180
* @param string $path
191181
* @param string $imageName
192-
*
193182
* @return string
194183
*/
195184
public function getFilePath($path, $imageName)
@@ -204,7 +193,7 @@ public function getFilePath($path, $imageName)
204193
* @param bool $returnRelativePath
205194
* @return string
206195
*
207-
* @throws \Magento\Framework\Exception\LocalizedException
196+
* @throws LocalizedException
208197
*/
209198
public function moveFileFromTmp($imageName, $returnRelativePath = false)
210199
{
@@ -232,10 +221,7 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
232221
);
233222
} catch (\Exception $e) {
234223
$this->logger->critical($e);
235-
throw new \Magento\Framework\Exception\LocalizedException(
236-
__('Something went wrong while saving the file(s).'),
237-
$e
238-
);
224+
throw new LocalizedException(__('Something went wrong while saving the file(s).'), $e);
239225
}
240226

241227
return $returnRelativePath ? $baseImagePath : $imageName;
@@ -245,10 +231,9 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
245231
* Checking file for save and save it to tmp dir
246232
*
247233
* @param string $fileId
248-
*
249234
* @return string[]
250235
*
251-
* @throws \Magento\Framework\Exception\LocalizedException
236+
* @throws LocalizedException
252237
*/
253238
public function saveFileToTmpDir($fileId)
254239
{
@@ -259,15 +244,13 @@ public function saveFileToTmpDir($fileId)
259244
$uploader->setAllowedExtensions($this->getAllowedExtensions());
260245
$uploader->setAllowRenameFiles(true);
261246
if (!$uploader->checkMimeType($this->allowedMimeTypes)) {
262-
throw new \Magento\Framework\Exception\LocalizedException(__('File validation failed.'));
247+
throw new LocalizedException(__('File validation failed.'));
263248
}
264249
$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));
265250
unset($result['path']);
266251

267252
if (!$result) {
268-
throw new \Magento\Framework\Exception\LocalizedException(
269-
__('File can not be saved to the destination folder.')
270-
);
253+
throw new LocalizedException(__('File can not be saved to the destination folder.'));
271254
}
272255

273256
/**
@@ -287,7 +270,7 @@ public function saveFileToTmpDir($fileId)
287270
$this->coreFileStorageDatabase->saveFile($relativePath);
288271
} catch (\Exception $e) {
289272
$this->logger->critical($e);
290-
throw new \Magento\Framework\Exception\LocalizedException(
273+
throw new LocalizedException(
291274
__('Something went wrong while saving the file(s).'),
292275
$e
293276
);

0 commit comments

Comments
 (0)