Skip to content

Commit 7900123

Browse files
authored
Merge pull request #7322 from magento-trigger/ph-delivery
[Platform Health] PHP 8.1 Updates
2 parents cff8851 + a475162 commit 7900123

File tree

26 files changed

+351
-168
lines changed

26 files changed

+351
-168
lines changed

app/code/Magento/Bundle/Pricing/Price/BundleRegularPrice.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\Bundle\Pricing\Price;
88

99
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
10-
use Magento\Catalog\Model\Product;
1110
use Magento\Framework\Pricing\Amount\AmountInterface;
1211
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
1312
use Magento\Bundle\Model\Product\Price;
@@ -27,36 +26,22 @@ class BundleRegularPrice extends \Magento\Catalog\Pricing\Price\RegularPrice imp
2726
*/
2827
protected $maximalPrice;
2928

30-
/**
31-
* @param Product $saleableItem
32-
* @param float $quantity
33-
* @param BundleCalculatorInterface $calculator
34-
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
35-
*/
36-
public function __construct(
37-
Product $saleableItem,
38-
$quantity,
39-
BundleCalculatorInterface $calculator,
40-
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
41-
) {
42-
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
43-
}
44-
4529
/**
4630
* @inheritdoc
4731
*/
4832
public function getAmount()
4933
{
50-
if (!isset($this->amount[$this->getValue()])) {
51-
$price = $this->getValue();
34+
$price = $this->getValue();
35+
$valueIndex = (string) $price;
36+
if (!isset($this->amount[$valueIndex])) {
5237
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
5338
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
5439
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
5540
$price += $customOptionPrice->getCustomOptionRange(true, $this->getPriceCode());
5641
}
57-
$this->amount[$this->getValue()] = $this->calculator->getMinRegularAmount($price, $this->product);
42+
$this->amount[$valueIndex] = $this->calculator->getMinRegularAmount($price, $this->product);
5843
}
59-
return $this->amount[$this->getValue()];
44+
return $this->amount[$valueIndex];
6045
}
6146

6247
/**

app/code/Magento/Bundle/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
</argument>
7373
</arguments>
7474
</type>
75+
<type name="Magento\Bundle\Pricing\Price\BundleRegularPrice">
76+
<arguments>
77+
<argument name="calculator" xsi:type="object">Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface</argument>
78+
</arguments>
79+
</type>
7580
<type name="Magento\Bundle\Pricing\Price\FinalPrice">
7681
<arguments>
7782
<argument name="calculator" xsi:type="object">Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface</argument>

app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Exception\LocalizedException;
1212

1313
/**
14-
* Class Upload
14+
* The product gallery upload controller
1515
*/
1616
class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterface
1717
{
@@ -20,7 +20,7 @@ class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterf
2020
*
2121
* @see _isAllowed()
2222
*/
23-
const ADMIN_RESOURCE = 'Magento_Catalog::products';
23+
public const ADMIN_RESOURCE = 'Magento_Catalog::products';
2424

2525
/**
2626
* @var \Magento\Framework\Controller\Result\RawFactory
@@ -97,17 +97,20 @@ public function execute()
9797
$result = $uploader->save(
9898
$mediaDirectory->getAbsolutePath($this->productMediaConfig->getBaseTmpMediaPath())
9999
);
100-
101100
$this->_eventManager->dispatch(
102101
'catalog_product_gallery_upload_image_after',
103102
['result' => $result, 'action' => $this]
104103
);
105104

106-
unset($result['tmp_name']);
107-
unset($result['path']);
105+
if (is_array($result)) {
106+
unset($result['tmp_name']);
107+
unset($result['path']);
108108

109-
$result['url'] = $this->productMediaConfig->getTmpMediaUrl($result['file']);
110-
$result['file'] = $result['file'] . '.tmp';
109+
$result['url'] = $this->productMediaConfig->getTmpMediaUrl($result['file']);
110+
$result['file'] = $result['file'] . '.tmp';
111+
} else {
112+
$result = ['error' => 'Something went wrong while saving the file(s).'];
113+
}
111114
} catch (LocalizedException $e) {
112115
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
113116
} catch (\Throwable $e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ public function saveFileToTmpDir($fileId)
247247
throw new LocalizedException(__('File validation failed.'));
248248
}
249249
$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));
250-
unset($result['path']);
251250

252251
if (!$result) {
253252
throw new LocalizedException(__('File can not be saved to the destination folder.'));
254253
}
254+
unset($result['path']);
255255

256256
/**
257257
* Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Exception\FileSystemException;
11+
use Magento\Framework\Exception\LocalizedException;
1012
use Magento\Framework\Exception\ValidatorException;
1113
use Magento\Framework\Filesystem;
1214
use Magento\Framework\Filesystem\Directory\TargetDirectory;
@@ -56,18 +58,14 @@ class Uploader extends \Magento\MediaStorage\Model\File\Uploader
5658
'png' => 'image/png',
5759
];
5860

59-
const DEFAULT_FILE_TYPE = 'application/octet-stream';
61+
public const DEFAULT_FILE_TYPE = 'application/octet-stream';
6062

6163
/**
62-
* Image factory.
63-
*
6464
* @var \Magento\Framework\Image\AdapterFactory
6565
*/
6666
protected $_imageFactory;
6767

6868
/**
69-
* Validator.
70-
*
7169
* @var \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension
7270
*/
7371
protected $_validator;
@@ -114,6 +112,8 @@ class Uploader extends \Magento\MediaStorage\Model\File\Uploader
114112

115113
/**
116114
* Directory and filename must be no more than 255 characters in length
115+
*
116+
* @var int
117117
*/
118118
private $maxFilenameLength = 255;
119119

@@ -132,8 +132,8 @@ class Uploader extends \Magento\MediaStorage\Model\File\Uploader
132132
* @param string|null $filePath
133133
* @param \Magento\Framework\Math\Random|null $random
134134
* @param TargetDirectory|null $targetDirectory
135-
* @throws \Magento\Framework\Exception\FileSystemException
136-
* @throws \Magento\Framework\Exception\LocalizedException
135+
* @throws FileSystemException
136+
* @throws LocalizedException
137137
*/
138138
public function __construct(
139139
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDb,
@@ -182,7 +182,7 @@ public function init()
182182
* @param string $fileName
183183
* @param bool $renameFileOff
184184
* @return array
185-
* @throws \Magento\Framework\Exception\LocalizedException
185+
* @throws LocalizedException
186186
*/
187187
public function move($fileName, $renameFileOff = false)
188188
{
@@ -197,17 +197,20 @@ public function move($fileName, $renameFileOff = false)
197197
}
198198

199199
$this->_setUploadFile($tmpFilePath);
200-
$rootDirectory = $this->getTargetDirectory()->getDirectoryRead(DirectoryList::ROOT);
200+
$rootDirectory = $this->targetDirectory->getDirectoryRead(DirectoryList::ROOT);
201201
$destDir = $rootDirectory->getAbsolutePath($this->getDestDir());
202202
$result = $this->save($destDir);
203-
unset($result['path']);
204-
$result['name'] = self::getCorrectFileName($result['name']);
205203

206-
// Directory and filename must be no more than 255 characters in length
207-
if (strlen($result['file']) > $this->maxFilenameLength) {
208-
throw new \LengthException(
209-
__('Filename is too long; must be %1 characters or less', $this->maxFilenameLength)
210-
);
204+
if (\is_array($result)) {
205+
unset($result['path']);
206+
$result['name'] = self::getCorrectFileName($result['name']);
207+
208+
// Directory and filename must be no more than 255 characters in length
209+
if (strlen($result['file']) > $this->maxFilenameLength) {
210+
throw new \LengthException(
211+
__('Filename is too long; must be %1 characters or less', $this->maxFilenameLength)
212+
);
213+
}
211214
}
212215

213216
return $result;
@@ -219,29 +222,30 @@ public function move($fileName, $renameFileOff = false)
219222
* @param string $url
220223
* @param string $driver
221224
* @return string
222-
* @throws \Magento\Framework\Exception\LocalizedException
225+
* @throws LocalizedException
223226
*/
224227
private function downloadFileFromUrl($url, $driver)
225228
{
226229
$parsedUrlPath = parse_url($url, PHP_URL_PATH);
230+
227231
if (!$parsedUrlPath) {
228-
throw new \Magento\Framework\Exception\LocalizedException(__('Could not parse resource url.'));
232+
throw new LocalizedException(__('Could not parse resource url.'));
229233
}
230234
$urlPathValues = explode('/', $parsedUrlPath);
231235
$fileName = preg_replace('/[^a-z0-9\._-]+/i', '', end($urlPathValues));
232-
236+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
233237
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
238+
234239
if ($fileExtension && !$this->checkAllowedExtension($fileExtension)) {
235-
throw new \Magento\Framework\Exception\LocalizedException(__('Disallowed file type.'));
240+
throw new LocalizedException(__('Disallowed file type.'));
236241
}
237-
238242
$tmpFileName = str_replace(".$fileExtension", '', $fileName);
239243
$tmpFileName .= '_' . $this->random->getRandomString(16);
240244
$tmpFileName .= $fileExtension ? ".$fileExtension" : '';
241245
$tmpFilePath = $this->_directory->getRelativePath($this->getTempFilePath($tmpFileName));
242246

243247
if (!$this->_directory->isWritable($this->getTmpDir())) {
244-
throw new \Magento\Framework\Exception\LocalizedException(
248+
throw new LocalizedException(
245249
__('Import images directory must be writable in order to process remote images.')
246250
);
247251
}
@@ -253,26 +257,12 @@ private function downloadFileFromUrl($url, $driver)
253257
return $tmpFilePath;
254258
}
255259

256-
/**
257-
* Retrieves target directory.
258-
*
259-
* @return TargetDirectory
260-
*/
261-
private function getTargetDirectory(): TargetDirectory
262-
{
263-
if (!isset($this->targetDirectory)) {
264-
$this->targetDirectory = ObjectManager::getInstance()->get(TargetDirectory::class);
265-
}
266-
267-
return $this->targetDirectory;
268-
}
269-
270260
/**
271261
* Prepare information about the file for moving
272262
*
273263
* @param string $filePath
274264
* @return void
275-
* @throws \Magento\Framework\Exception\LocalizedException
265+
* @throws LocalizedException
276266
*/
277267
protected function _setUploadFile($filePath)
278268
{
@@ -290,7 +280,7 @@ protected function _setUploadFile($filePath)
290280
$readable = false;
291281
}
292282
if (!$readable) {
293-
throw new \Magento\Framework\Exception\LocalizedException(
283+
throw new LocalizedException(
294284
__('File \'%1\' was not found or has read restriction.', $filePath)
295285
);
296286
}
@@ -322,7 +312,7 @@ protected function _readFileInfo($filePath)
322312
* Validate uploaded file by type and etc.
323313
*
324314
* @return void
325-
* @throws \Magento\Framework\Exception\LocalizedException
315+
* @throws LocalizedException
326316
*/
327317
protected function _validateFile()
328318
{
@@ -335,7 +325,7 @@ protected function _validateFile()
335325

336326
$fileExtension = pathinfo($filePath, PATHINFO_EXTENSION);
337327
if (!$this->checkAllowedExtension($fileExtension)) {
338-
throw new \Magento\Framework\Exception\LocalizedException(__('Disallowed file type.'));
328+
throw new LocalizedException(__('Disallowed file type.'));
339329
}
340330
//run validate callbacks
341331
foreach ($this->_validateCallbacks as $params) {
@@ -405,7 +395,7 @@ public function getDestDir()
405395
*/
406396
public function setDestDir($path)
407397
{
408-
$directoryRoot = $this->getTargetDirectory()->getDirectoryWrite(DirectoryList::ROOT);
398+
$directoryRoot = $this->targetDirectory->getDirectoryWrite(DirectoryList::ROOT);
409399
if (is_string($path) && $directoryRoot->isWritable($path)) {
410400
$this->_destDir = $path;
411401
return true;
@@ -429,7 +419,7 @@ protected function _moveFile($tmpPath, $destPath)
429419
$destinationRealPath = $this->_directory->getDriver()->getRealPath($destPath);
430420
$relativeDestPath = $this->_directory->getRelativePath($destPath);
431421
$isSameFile = $tmpRealPath === $destinationRealPath;
432-
$rootDirectory = $this->getTargetDirectory()->getDirectoryWrite(DirectoryList::ROOT);
422+
$rootDirectory = $this->targetDirectory->getDirectoryWrite(DirectoryList::ROOT);
433423
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $relativeDestPath, $rootDirectory);
434424
} else {
435425
return false;

app/code/Magento/Config/Model/Config/Backend/File.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
*/
66
namespace Magento\Config\Model\Config\Backend;
77

8+
use Exception;
89
use Magento\Framework\App\Config\ScopeConfigInterface;
910
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Exception\LocalizedException;
1012
use Magento\Framework\Filesystem;
1113
use Magento\MediaStorage\Model\File\Uploader;
1214

@@ -82,12 +84,13 @@ public function __construct(
8284
* Save uploaded file before saving config value
8385
*
8486
* @return $this
85-
* @throws \Magento\Framework\Exception\LocalizedException
87+
* @throws LocalizedException
8688
*/
8789
public function beforeSave()
8890
{
8991
$value = $this->getValue();
9092
$file = $this->getFileData();
93+
9194
if (!empty($file)) {
9295
$uploadDir = $this->_getUploadDir();
9396
try {
@@ -97,12 +100,11 @@ public function beforeSave()
97100
$uploader->setAllowRenameFiles(true);
98101
$uploader->addValidateCallback('size', $this, 'validateMaxSize');
99102
$result = $uploader->save($uploadDir);
100-
} catch (\Exception $e) {
101-
throw new \Magento\Framework\Exception\LocalizedException(__('%1', $e->getMessage()));
103+
} catch (Exception $e) {
104+
throw new LocalizedException(__('%1', $e->getMessage()));
102105
}
103-
104-
$filename = $result['file'];
105-
if ($filename) {
106+
if ($result !== false) {
107+
$filename = $result['file'];
106108
if ($this->_addWhetherScopeInfo()) {
107109
$filename = $this->_prependScopeInfo($filename);
108110
}
@@ -148,7 +150,7 @@ protected function getFileData()
148150
*
149151
* @param string $filePath Path to temporary uploaded file
150152
* @return void
151-
* @throws \Magento\Framework\Exception\LocalizedException
153+
* @throws LocalizedException
152154
*/
153155
public function validateMaxSize($filePath)
154156
{
@@ -157,7 +159,7 @@ public function validateMaxSize($filePath)
157159
$directory->getRelativePath($filePath)
158160
)['size'] > $this->_maxFileSize * 1024
159161
) {
160-
throw new \Magento\Framework\Exception\LocalizedException(
162+
throw new LocalizedException(
161163
__('The file you\'re uploading exceeds the server size limit of %1 kilobytes.', $this->_maxFileSize)
162164
);
163165
}
@@ -179,14 +181,14 @@ protected function _addWhetherScopeInfo()
179181
* Return path to directory for upload file
180182
*
181183
* @return string
182-
* @throws \Magento\Framework\Exception\LocalizedException
184+
* @throws LocalizedException
183185
*/
184186
protected function _getUploadDir()
185187
{
186188
$fieldConfig = $this->getFieldConfig();
187189

188190
if (!array_key_exists('upload_dir', $fieldConfig)) {
189-
throw new \Magento\Framework\Exception\LocalizedException(
191+
throw new LocalizedException(
190192
__('The base directory to upload file is not specified.')
191193
);
192194
}

0 commit comments

Comments
 (0)