Skip to content

Commit d84a0f0

Browse files
committed
Merge remote-tracking branch 'anzin/php8-compatibility/fix-round-and-abs-function' into platform-health
2 parents 29fed52 + cba03f0 commit d84a0f0

File tree

32 files changed

+235
-118
lines changed

32 files changed

+235
-118
lines changed

app/code/Magento/AdvancedSearch/Model/ResourceModel/Index.php

Lines changed: 4 additions & 1 deletion
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;

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

Lines changed: 75 additions & 0 deletions
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
}

app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php

Lines changed: 8 additions & 7 deletions
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;

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item.php

Lines changed: 1 addition & 1 deletion
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
}

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

Lines changed: 2 additions & 2 deletions
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;

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 4 additions & 4 deletions
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) {

app/code/Magento/Directory/Model/PriceCurrency.php

Lines changed: 1 addition & 1 deletion
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
}

app/code/Magento/Directory/Model/ResourceModel/Currency.php

Lines changed: 1 addition & 1 deletion
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
}

app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate/RateQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getBindings()
108108
}
109109
} else {
110110
$bind[':condition_name'] = $this->request->getConditionName();
111-
$bind[':condition_value'] = round($this->request->getData($this->request->getConditionName()), 4);
111+
$bind[':condition_value'] = round((float) $this->request->getData($this->request->getConditionName()), 4);
112112
}
113113

114114
return $bind;

app/code/Magento/Payment/Model/Cart.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
namespace Magento\Payment\Model;
77

8+
use Magento\Framework\DataObject;
9+
use Magento\Framework\Event\ManagerInterface;
10+
use Magento\Payment\Model\Cart\SalesModel\Factory;
11+
use Magento\Payment\Model\Cart\SalesModel\SalesModelInterface;
12+
use Magento\Quote\Api\Data\CartInterface;
13+
814
/**
915
* Provide methods for collecting cart items information of specific sales model entity
1016
*
@@ -25,13 +31,15 @@ class Cart
2531
const AMOUNT_SUBTOTAL = 'subtotal';
2632
/**#@-*/
2733

28-
/**#@-*/
34+
/**
35+
* @var SalesModelInterface
36+
*/
2937
protected $_salesModel;
3038

3139
/**
3240
* Core event manager proxy
3341
*
34-
* @var \Magento\Framework\Event\ManagerInterface
42+
* @var ManagerInterface
3543
*/
3644
protected $_eventManager;
3745

@@ -71,13 +79,13 @@ class Cart
7179
protected $_itemsCollectingRequired = true;
7280

7381
/**
74-
* @param \Magento\Payment\Model\Cart\SalesModel\Factory $salesModelFactory
75-
* @param \Magento\Framework\Event\ManagerInterface $eventManager
76-
* @param \Magento\Quote\Api\Data\CartInterface $salesModel
82+
* @param Factory $salesModelFactory
83+
* @param ManagerInterface $eventManager
84+
* @param CartInterface $salesModel
7785
*/
7886
public function __construct(
79-
\Magento\Payment\Model\Cart\SalesModel\Factory $salesModelFactory,
80-
\Magento\Framework\Event\ManagerInterface $eventManager,
87+
Factory $salesModelFactory,
88+
ManagerInterface $eventManager,
8189
$salesModel
8290
) {
8391
$this->_eventManager = $eventManager;
@@ -88,7 +96,7 @@ public function __construct(
8896
/**
8997
* Return payment cart sales model
9098
*
91-
* @return \Magento\Payment\Model\Cart\SalesModel\SalesModelInterface
99+
* @return SalesModelInterface
92100
* @api
93101
*/
94102
public function getSalesModel()
@@ -335,7 +343,7 @@ protected function _importItemsFromSalesModel()
335343
$this->addSubtotal($this->_salesModel->getBaseSubtotal());
336344
$this->addTax($this->_salesModel->getBaseTaxAmount());
337345
$this->addShipping($this->_salesModel->getBaseShippingAmount());
338-
$this->addDiscount(abs($this->_salesModel->getBaseDiscountAmount()));
346+
$this->addDiscount(abs((float) $this->_salesModel->getBaseDiscountAmount()));
339347
}
340348

341349
/**
@@ -361,6 +369,8 @@ protected function _calculateCustomItemsSubtotal()
361369
}
362370

363371
/**
372+
* Method for set transfer flag.
373+
*
364374
* @param string $flagType
365375
* @param bool $value
366376
* @return void
@@ -372,6 +382,8 @@ protected function _setTransferFlag($flagType, $value)
372382
}
373383

374384
/**
385+
* Method for set amount.
386+
*
375387
* @param string $amountType
376388
* @param float $amount
377389
* @return void
@@ -382,6 +394,8 @@ protected function _setAmount($amountType, $amount)
382394
}
383395

384396
/**
397+
* Method for add amount.
398+
*
385399
* @param string $amountType
386400
* @param float $amount
387401
* @return void
@@ -409,11 +423,11 @@ protected function _getAmount($amountType)
409423
* @param int $qty
410424
* @param float $amount
411425
* @param null|string $identifier
412-
* @return \Magento\Framework\DataObject
426+
* @return DataObject
413427
*/
414428
protected function _createItemFromData($name, $qty, $amount, $identifier = null)
415429
{
416-
$item = new \Magento\Framework\DataObject(['name' => $name, 'qty' => $qty, 'amount' => (double)$amount]);
430+
$item = new DataObject(['name' => $name, 'qty' => $qty, 'amount' => (double)$amount]);
417431

418432
if ($identifier) {
419433
$item->setData('id', $identifier);

0 commit comments

Comments
 (0)