Skip to content

Commit 8cdefb0

Browse files
authored
Merge pull request #7128 from magento-commerce/platform-health
[Platform Health] PHP 8 compatibility fixes
2 parents 9d69186 + 4912aa7 commit 8cdefb0

File tree

60 files changed

+2683
-592
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2683
-592
lines changed

Diff for: app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ public function __construct(
8080

8181
/**
8282
* Implementation of abstract construct
83+
*
8384
* @return void
8485
* @since 100.1.0
86+
* phpcs:disable Magento2.CodeAnalysis.EmptyBlock
8587
*/
8688
protected function _construct()
8789
{
@@ -118,7 +120,8 @@ protected function _getCatalogProductPriceData($productIds = null)
118120

119121
$result = [];
120122
foreach ($connection->fetchAll($catalogProductIndexPriceUnionSelect) as $row) {
121-
$result[$row['website_id']][$row['entity_id']][$row['customer_group_id']] = round($row['min_price'], 2);
123+
$result[$row['website_id']][$row['entity_id']][$row['customer_group_id']] =
124+
round((float) $row['min_price'], 2);
122125
}
123126

124127
return $result;

Diff for: app/code/Magento/AdvancedSearch/Test/Unit/Model/ResourceModel/IndexTest.php

+75
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class IndexTest extends TestCase
6060
*/
6161
private $resourceConnectionMock;
6262

63+
/**
64+
* @inheritdoc
65+
*/
6366
protected function setUp(): void
6467
{
6568
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
@@ -98,6 +101,9 @@ protected function setUp(): void
98101
);
99102
}
100103

104+
/**
105+
* @return void
106+
*/
101107
public function testGetPriceIndexDataUsesFrontendPriceIndexerTable(): void
102108
{
103109
$storeId = 1;
@@ -117,4 +123,73 @@ public function testGetPriceIndexDataUsesFrontendPriceIndexerTable(): void
117123

118124
$this->assertEmpty($this->model->getPriceIndexData([1], $storeId));
119125
}
126+
127+
/**
128+
* @param array $testData
129+
* @dataProvider providerForTestPriceIndexData
130+
*
131+
* @return void
132+
*/
133+
public function testGetPriceIndexData(array $testData): void
134+
{
135+
$storeMock = $this->getMockForAbstractClass(StoreInterface::class);
136+
$storeMock->expects($this->any())->method('getId')->willReturn(1);
137+
$storeMock->method('getWebsiteId')->willReturn($testData['website_id']);
138+
$this->storeManagerMock->expects($this->once())
139+
->method('getStore')
140+
->with(1)->willReturn($storeMock);
141+
142+
$selectMock = $this->createMock(Select::class);
143+
$selectMock->expects($this->any())->method('union')->willReturnSelf();
144+
$this->adapterMock->expects($this->any())->method('select')->willReturn($selectMock);
145+
$this->adapterMock->expects($this->any())->method('fetchAll')->with($selectMock)->willReturn([$testData]);
146+
$expectedData = [
147+
$testData['entity_id'] => [
148+
$testData['customer_group_id'] => round((float) $testData['min_price'], 2)
149+
]
150+
];
151+
152+
$this->assertEquals($this->model->getPriceIndexData([1], 1), $expectedData);
153+
}
154+
155+
/**
156+
* @return array
157+
*/
158+
public function providerForTestPriceIndexData(): array
159+
{
160+
return [
161+
[
162+
[
163+
'website_id' => 1,
164+
'entity_id' => 1,
165+
'customer_group_id' => 1,
166+
'min_price' => '12.12'
167+
]
168+
],
169+
[
170+
[
171+
'website_id' => 1,
172+
'entity_id' => 2,
173+
'customer_group_id' => 2,
174+
'min_price' => null
175+
]
176+
],
177+
[
178+
[
179+
'website_id' => 1,
180+
'entity_id' => 3,
181+
'customer_group_id' => 3,
182+
'min_price' => 12.12
183+
]
184+
],
185+
[
186+
[
187+
'website_id' => 1,
188+
'entity_id' => 3,
189+
'customer_group_id' => 3,
190+
'min_price' => ''
191+
]
192+
]
193+
];
194+
}
120195
}

Diff for: app/code/Magento/Bundle/Model/Product/SelectionProductsDisabledRequired.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function __construct(
8282
* @param int $bundleId
8383
* @param int|null $websiteId
8484
* @return array
85+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8586
*/
8687
public function getChildProductIds(int $bundleId, ?int $websiteId = null): array
8788
{
@@ -128,10 +129,12 @@ public function getChildProductIds(int $bundleId, ?int $websiteId = null): array
128129
private function getProducts(array $selectionProductIds, int $websiteId): array
129130
{
130131
$productIds = [];
131-
$defaultStoreId = $this->storeManager->getWebsite($websiteId)->getDefaultStore()->getId();
132+
$defaultStore = $this->storeManager->getWebsite($websiteId)->getDefaultStore();
133+
$defaultStoreId = $defaultStore ? $defaultStore->getId() : null;
132134
foreach ($selectionProductIds as $optionProductIds) {
133-
$productIds = array_merge($productIds, $optionProductIds);
135+
$productIds[] = $optionProductIds;
134136
}
137+
$productIds = array_merge([], ...$productIds);
135138
$productCollection = $this->productCollectionFactory->create();
136139
$productCollection->joinAttribute(
137140
ProductInterface::STATUS,

Diff for: app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Store\Model\StoreManagerInterface;
1313

1414
/**
15-
* Class Save
15+
* Category save controller
1616
*
1717
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1818
*/
@@ -144,10 +144,10 @@ public function execute()
144144
$categoryPostData = $this->stringToBoolConverting($categoryPostData);
145145
$categoryPostData = $this->imagePreprocessing($categoryPostData);
146146
$categoryPostData = $this->dateTimePreprocessing($category, $categoryPostData);
147-
$storeId = isset($categoryPostData['store_id']) ? $categoryPostData['store_id'] : null;
147+
$storeId = $categoryPostData['store_id'] ?? null;
148148
$store = $this->storeManager->getStore($storeId);
149149
$this->storeManager->setCurrentStore($store->getCode());
150-
$parentId = isset($categoryPostData['parent']) ? $categoryPostData['parent'] : null;
150+
$parentId = $categoryPostData['parent'] ?? null;
151151
if ($categoryPostData) {
152152
$category->addData($categoryPostData);
153153
if ($parentId) {
@@ -168,7 +168,7 @@ public function execute()
168168
if (isset($categoryPostData['use_config']) && !empty($categoryPostData['use_config'])) {
169169
foreach ($categoryPostData['use_config'] as $attributeCode => $attributeValue) {
170170
if ($attributeValue) {
171-
$useConfig[] = $attributeCode;
171+
$useConfig[] = $attributeValue;
172172
$category->setData($attributeCode, null);
173173
}
174174
}
@@ -220,7 +220,11 @@ public function execute()
220220
__('The "%1" attribute is required. Enter and try again.', $attribute)
221221
);
222222
} else {
223-
$this->messageManager->addErrorMessage(__('Something went wrong while saving the category.'));
223+
$this->messageManager->addErrorMessage(
224+
__(
225+
'Something went wrong while saving the category.'
226+
)
227+
);
224228
$this->logger->critical('Something went wrong while saving the category.');
225229
$this->_getSession()->setCategoryData($categoryPostData);
226230
}

Diff for: app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\App\ResourceConnection;
1414
use Magento\ImportExport\Model\Import;
1515
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
16+
use Magento\ImportExport\Model\ResourceModel\CollectionByPagesIterator;
1617
use Magento\Store\Model\Store;
1718

1819
/**
@@ -257,7 +258,9 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
257258

258259
/**#@-*/
259260

260-
/**#@-*/
261+
/**
262+
* @var CollectionByPagesIterator
263+
*/
261264
protected $_byPagesIterator;
262265

263266
/**
@@ -317,15 +320,11 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
317320
protected $dateTime;
318321

319322
/**
320-
* Product entity link field
321-
*
322323
* @var string
323324
*/
324325
private $productEntityLinkField;
325326

326327
/**
327-
* Product entity identifier field
328-
*
329328
* @var string
330329
*/
331330
private $productEntityIdentifierField;
@@ -1783,7 +1782,8 @@ protected function _getOptionData(array $rowData, $productId, $optionId, $type)
17831782
'product_id' => $productId,
17841783
'type' => $type,
17851784
'is_require' => empty($rowData[self::COLUMN_IS_REQUIRED]) ? 0 : 1,
1786-
'sort_order' => empty($rowData[self::COLUMN_SORT_ORDER]) ? 0 : abs($rowData[self::COLUMN_SORT_ORDER]),
1785+
'sort_order' => empty($rowData[self::COLUMN_SORT_ORDER]) ? 0
1786+
: abs((int) $rowData[self::COLUMN_SORT_ORDER]),
17871787
];
17881788

17891789
if (!$this->_isRowHasSpecificType($type)) {
@@ -1854,7 +1854,8 @@ protected function _getSpecificTypeData(array $rowData, $optionTypeId, $defaultS
18541854
if (!empty($rowData[self::COLUMN_ROW_TITLE]) && $defaultStore && empty($rowData[self::COLUMN_STORE])) {
18551855
$valueData = [
18561856
'option_type_id' => $optionTypeId,
1857-
'sort_order' => empty($rowData[self::COLUMN_ROW_SORT]) ? 0 : abs($rowData[self::COLUMN_ROW_SORT]),
1857+
'sort_order' => empty($rowData[self::COLUMN_ROW_SORT]) ? 0
1858+
: abs((int) $rowData[self::COLUMN_ROW_SORT]),
18581859
'sku' => !empty($rowData[self::COLUMN_ROW_SKU]) ? $rowData[self::COLUMN_ROW_SKU] : '',
18591860
];
18601861
$data['value'] = $valueData;

Diff for: app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function _prepareDataForTable(\Magento\Framework\DataObject $object, $
132132
if ($object->getQty() === null) {
133133
$data['qty'] = null;
134134
} elseif ($object->getQtyCorrection() < 0) {
135-
$data['qty'] = new \Zend_Db_Expr($ifNullSql . '-' . abs($object->getQtyCorrection()));
135+
$data['qty'] = new \Zend_Db_Expr($ifNullSql . '-' . abs((float) $object->getQtyCorrection()));
136136
} else {
137137
$data['qty'] = new \Zend_Db_Expr($ifNullSql . '+' . $object->getQtyCorrection());
138138
}

Diff for: app/code/Magento/Config/Console/Command/EmulatedAdminhtmlAreaProcessor.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Config\Console\Command;
77

8+
use Exception;
89
use Magento\Framework\App\Area;
910
use Magento\Framework\App\State;
1011
use Magento\Framework\Config\ScopeInterface;
@@ -48,17 +49,18 @@ public function __construct(ScopeInterface $scope, State $state)
4849
* @param array $params The parameters to be passed to the callback, as an indexed array
4950
* @return bool|int|float|string|array|null - as the result of this method is the result of callback,
5051
* you can use callback only with specified in this method return types
51-
* @throws \Exception The exception is thrown if the parameter $callback throws an exception
52+
* @throws Exception The exception is thrown if the parameter $callback throws an exception
5253
*/
5354
public function process(callable $callback, array $params = [])
5455
{
5556
$currentScope = $this->scope->getCurrentScope();
5657
try {
5758
return $this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($callback, $params) {
5859
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
59-
return call_user_func_array($callback, $params);
60+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
61+
return call_user_func_array($callback, array_values($params));
6062
});
61-
} catch (\Exception $exception) {
63+
} catch (Exception $exception) {
6264
throw $exception;
6365
} finally {
6466
$this->scope->setCurrentScope($currentScope);

Diff for: app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/SaveRates.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1010

1111
/**
12-
* Class SaveRates
12+
* Class for save rates.
1313
*/
1414
class SaveRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency implements HttpPostActionInterface
1515
{
@@ -26,7 +26,7 @@ public function execute()
2626
foreach ($data as $currencyCode => $rate) {
2727
foreach ($rate as $currencyTo => $value) {
2828
$value = abs(
29-
$this->_objectManager->get(\Magento\Framework\Locale\FormatInterface::class)
29+
(float) $this->_objectManager->get(\Magento\Framework\Locale\FormatInterface::class)
3030
->getNumber($value)
3131
);
3232
$data[$currencyCode][$currencyTo] = $value;

Diff for: app/code/Magento/Dhl/Model/Carrier.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin
210210
protected $_httpClientFactory;
211211

212212
/**
213-
* @inheritdoc
213+
* @var string[]
214214
*/
215215
protected $_debugReplacePrivateDataKeys = [
216216
'SiteID', 'Password'
@@ -1748,9 +1748,9 @@ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
17481748
$nodePiece->addChild('Weight', sprintf('%.3f', $package['params']['weight']));
17491749
$params = $package['params'];
17501750
if ($params['width'] && $params['length'] && $params['height']) {
1751-
$nodePiece->addChild('Width', round($params['width']));
1752-
$nodePiece->addChild('Height', round($params['height']));
1753-
$nodePiece->addChild('Depth', round($params['length']));
1751+
$nodePiece->addChild('Width', (string) round((float) $params['width']));
1752+
$nodePiece->addChild('Height', (string) round((float) $params['height']));
1753+
$nodePiece->addChild('Depth', (string) round((float) $params['length']));
17541754
}
17551755
$content = [];
17561756
foreach ($package['items'] as $item) {

Diff for: app/code/Magento/Directory/Model/PriceCurrency.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ public function round($price)
164164
*/
165165
public function roundPrice($price, $precision = self::DEFAULT_PRECISION)
166166
{
167-
return round($price, $precision);
167+
return round((float) $price, $precision);
168168
}
169169
}

Diff for: app/code/Magento/Directory/Model/ResourceModel/Currency.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function saveRates($rates)
143143
$data = [];
144144
foreach ($rates as $currencyCode => $rate) {
145145
foreach ($rate as $currencyTo => $value) {
146-
$value = abs($value);
146+
$value = abs((float) $value);
147147
if ($value == 0) {
148148
continue;
149149
}

Diff for: app/code/Magento/Eav/Model/Entity/AbstractEntity.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class AbstractEntity extends AbstractResource implements EntityInterfac
4343
protected $attributeLoader;
4444

4545
/**
46-
* Connection name
46+
* The connection name.
4747
*
4848
* @var string
4949
*/
@@ -226,11 +226,13 @@ abstract class AbstractEntity extends AbstractResource implements EntityInterfac
226226
* @param Context $context
227227
* @param array $data
228228
* @param UniqueValidationInterface|null $uniqueValidator
229+
* @param AttributeLoaderInterface|null $attributeLoader
229230
*/
230231
public function __construct(
231232
Context $context,
232233
$data = [],
233-
UniqueValidationInterface $uniqueValidator = null
234+
UniqueValidationInterface $uniqueValidator = null,
235+
AttributeLoaderInterface $attributeLoader = null
234236
) {
235237
$this->_eavConfig = $context->getEavConfig();
236238
$this->_resource = $context->getResource();
@@ -240,8 +242,10 @@ public function __construct(
240242
$this->_universalFactory = $context->getUniversalFactory();
241243
$this->transactionManager = $context->getTransactionManager();
242244
$this->objectRelationProcessor = $context->getObjectRelationProcessor();
243-
$this->uniqueValidator = $uniqueValidator ?:
244-
ObjectManager::getInstance()->get(UniqueValidationInterface::class);
245+
$this->uniqueValidator = $uniqueValidator
246+
?: ObjectManager::getInstance()->get(UniqueValidationInterface::class);
247+
$this->attributeLoader = $attributeLoader
248+
?: ObjectManager::getInstance()->get(AttributeLoaderInterface::class);
245249
parent::__construct();
246250
$properties = get_object_vars($this);
247251
foreach ($data as $key => $value) {
@@ -547,7 +551,7 @@ public function isPartialSave($flag = null)
547551
*/
548552
public function loadAllAttributes($object = null)
549553
{
550-
return $this->getAttributeLoader()->loadAllAttributes($this, $object);
554+
return $this->attributeLoader->loadAllAttributes($this, $object);
551555
}
552556

553557
/**
@@ -677,7 +681,7 @@ public function walkAttributes($partMethod, array $args = [], $collectExceptionM
677681

678682
try {
679683
// phpcs:disable Magento2.Functions.DiscouragedFunction
680-
$results[$attrCode] = call_user_func_array([$instance, $method], $args);
684+
$results[$attrCode] = call_user_func_array([$instance, $method], array_values($args));
681685
} catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) {
682686
if ($collectExceptionMessages) {
683687
$results[$attrCode] = $e->getMessage();
@@ -1928,9 +1932,6 @@ protected function _isAttributeValueEmpty(AbstractAttribute $attribute, $value)
19281932
*/
19291933
protected function getAttributeLoader()
19301934
{
1931-
if ($this->attributeLoader === null) {
1932-
$this->attributeLoader= ObjectManager::getInstance()->get(AttributeLoaderInterface::class);
1933-
}
19341935
return $this->attributeLoader;
19351936
}
19361937

0 commit comments

Comments
 (0)