Skip to content

Commit 92c4490

Browse files
author
silinmykola
committed
Fix magento codebase for Integration Tests to be compatible with PHP 8.1
1 parent 0af0fba commit 92c4490

File tree

15 files changed

+99
-122
lines changed

15 files changed

+99
-122
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/tabs.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
endif;
2626
?>
2727
<?php $_tabClass = 'tab-item-link ' . $block->getTabClass($_tab) . ' ' .
28-
(preg_match('/\s?ajax\s?/', $_tab->getClass()) ? 'notloaded' : '') ?>
28+
(preg_match('/\s?ajax\s?/', $_tab->getClass() ?? '') ? 'notloaded' : '') ?>
2929
<?php $_tabType = (!preg_match('/\s?ajax\s?/', $_tabClass) && $block->getTabUrl($_tab) != '#') ?
3030
'link' : '' ?>
3131
<?php $_tabHref = $block->getTabUrl($_tab) == '#' ? '#' . $block->getTabId($_tab) . '_content' :

app/code/Magento/Catalog/Model/Indexer/Product/Flat/TableBuilder.php

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Catalog\Model\Indexer\Product\Flat;
77

88
use Magento\Catalog\Model\Indexer\Product\Flat\Table\BuilderInterfaceFactory;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\EntityManager\MetadataPool;
911
use Magento\Store\Model\Store;
1012

1113
/**
@@ -26,7 +28,7 @@ class TableBuilder
2628
protected $_connection;
2729

2830
/**
29-
* @var \Magento\Framework\EntityManager\MetadataPool
31+
* @var MetadataPool
3032
*/
3133
protected $metadataPool;
3234

@@ -46,17 +48,20 @@ class TableBuilder
4648
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper
4749
* @param \Magento\Framework\App\ResourceConnection $resource
4850
* @param BuilderInterfaceFactory|null $tableBuilderFactory
51+
* @param MetadataPool|null $metadataPool
4952
*/
5053
public function __construct(
5154
\Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper,
5255
\Magento\Framework\App\ResourceConnection $resource,
53-
BuilderInterfaceFactory $tableBuilderFactory = null
56+
BuilderInterfaceFactory $tableBuilderFactory = null,
57+
MetadataPool $metadataPool = null
5458
) {
5559
$this->_productIndexerHelper = $productIndexerHelper;
5660
$this->resource = $resource;
5761
$this->_connection = $resource->getConnection();
58-
$this->tableBuilderFactory = $tableBuilderFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
62+
$this->tableBuilderFactory = $tableBuilderFactory ?: ObjectManager::getInstance()
5963
->get(BuilderInterfaceFactory::class);
64+
$this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
6065
}
6166

6267
/**
@@ -73,7 +78,7 @@ public function build($storeId, $changedIds, $valueFieldSuffix)
7378
$attributes = $this->_productIndexerHelper->getAttributes();
7479
$eavAttributes = $this->_productIndexerHelper->getTablesStructure($attributes);
7580
$entityTableColumns = $eavAttributes[$entityTableName];
76-
$linkField = $this->getMetadataPool()
81+
$linkField = $this->metadataPool
7782
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
7883
->getLinkField();
7984

@@ -226,7 +231,7 @@ protected function _fillTemporaryEntityTable($tableName, array $columns, array $
226231
if (!empty($columns)) {
227232
$select = $this->_connection->select();
228233
$temporaryEntityTable = $this->_getTemporaryTableName($tableName);
229-
$metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
234+
$metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
230235
$idsColumns = array_unique([$metadata->getLinkField(), 'entity_id', 'type_id', 'attribute_set_id']);
231236

232237
$columns = array_merge($idsColumns, array_keys($columns));
@@ -269,6 +274,7 @@ protected function _addPrimaryKeyToTable($tableName, $columnName = 'entity_id')
269274
* @param int $storeId
270275
* @return void
271276
* @throws \Exception
277+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
272278
*/
273279
protected function _fillTemporaryTable(
274280
$tableName,
@@ -278,7 +284,11 @@ protected function _fillTemporaryTable(
278284
$storeId
279285
) {
280286
if (!empty($tableColumns)) {
281-
$columnsChunks = array_chunk($tableColumns, Action\Indexer::ATTRIBUTES_CHUNK_SIZE / 2, true);
287+
$columnsChunks = array_chunk(
288+
$tableColumns,
289+
intdiv(Action\Indexer::ATTRIBUTES_CHUNK_SIZE, 2),
290+
true
291+
);
282292

283293
$entityTableName = $this->_productIndexerHelper->getTable('catalog_product_entity');
284294
$entityTemporaryTableName = $this->_getTemporaryTableName($entityTableName);
@@ -288,7 +298,7 @@ protected function _fillTemporaryTable(
288298

289299
$flatColumns = $this->_productIndexerHelper->getFlatColumns();
290300
$defaultStoreId = Store::DEFAULT_STORE_ID;
291-
$linkField = $this->getMetadataPool()
301+
$linkField = $this->metadataPool
292302
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
293303
->getLinkField();
294304

@@ -368,19 +378,4 @@ protected function _fillTemporaryTable(
368378
}
369379
}
370380
}
371-
372-
/**
373-
* Get Metadata Pool
374-
*
375-
* @return \Magento\Framework\EntityManager\MetadataPool
376-
* @deprecated 102.0.0
377-
*/
378-
private function getMetadataPool()
379-
{
380-
if (null === $this->metadataPool) {
381-
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
382-
->get(\Magento\Framework\EntityManager\MetadataPool::class);
383-
}
384-
return $this->metadataPool;
385-
}
386381
}

app/code/Magento/Catalog/Model/Product/Option/Type/Date.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function is24hTimeFormat()
340340
*/
341341
public function getYearStart()
342342
{
343-
$_range = explode(',', $this->getConfigData('year_range'));
343+
$_range = explode(',', $this->getConfigData('year_range') ?? '');
344344
if (isset($_range[0]) && !empty($_range[0])) {
345345
return $_range[0];
346346
} else {
@@ -355,7 +355,7 @@ public function getYearStart()
355355
*/
356356
public function getYearEnd()
357357
{
358-
$_range = explode(',', $this->getConfigData('year_range'));
358+
$_range = explode(',', $this->getConfigData('year_range') ?? '');
359359
if (isset($_range[1]) && !empty($_range[1])) {
360360
return $_range[1];
361361
} else {

app/code/Magento/Catalog/Model/Product/Option/Type/Text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function validateUserValue($values)
5858
parent::validateUserValue($values);
5959

6060
$option = $this->getOption();
61-
$value = trim($this->getUserValue());
61+
$value = ($this->getUserValue() !== null) ? trim($this->getUserValue()) : '';
6262

6363
// Check requires option to have some value
6464
if (strlen($value) == 0 && $option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {

app/code/Magento/Catalog/Ui/DataProvider/CatalogEavValidationRules.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ public function build(ProductAttributeInterface $attribute, array $data)
3333
$rules['validate-zero-or-greater'] = true;
3434
}
3535

36-
$validationClasses = explode(' ', $attribute->getFrontendClass());
36+
$validationClasses = explode(' ', $attribute->getFrontendClass() ?? '');
3737

3838
foreach ($validationClasses as $class) {
3939
if (preg_match('/^maximum-length-(\d+)$/', $class, $matches)) {
40+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
4041
$rules = array_merge($rules, ['max_text_length' => $matches[1]]);
4142
continue;
4243
}
4344
if (preg_match('/^minimum-length-(\d+)$/', $class, $matches)) {
45+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
4446
$rules = array_merge($rules, ['min_text_length' => $matches[1]]);
4547
continue;
4648
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
3030
{
31-
/**#@+
31+
/**
3232
* Custom option column names
3333
*/
3434
const COLUMN_SKU = 'sku';
@@ -53,8 +53,6 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
5353

5454
const COLUMN_ROW_SORT = '_custom_option_row_sort';
5555

56-
/**#@-*/
57-
5856
/**
5957
* XML path to page size parameter
6058
*/
@@ -231,7 +229,7 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
231229
*/
232230
protected $_optionCollection;
233231

234-
/**#@+
232+
/**
235233
* Error codes
236234
*/
237235
const ERROR_INVALID_STORE = 'optionInvalidStore';
@@ -256,8 +254,6 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
256254

257255
const ERROR_AMBIGUOUS_TYPES = 'optionAmbiguousTypes';
258256

259-
/**#@-*/
260-
261257
/**
262258
* @var CollectionByPagesIterator
263259
*/
@@ -271,8 +267,6 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
271267
protected $_pageSize;
272268

273269
/**
274-
* Catalog data
275-
*
276270
* @var \Magento\Catalog\Helper\Data
277271
*/
278272
protected $_catalogData = null;
@@ -1287,6 +1281,7 @@ protected function _importData()
12871281
$this->_rowProductId = $this->_productsSkuToId[$rowData[self::COLUMN_SKU]];
12881282
if (array_key_exists('custom_options', $rowData)
12891283
&& (
1284+
$rowData['custom_options'] === null ||
12901285
trim($rowData['custom_options']) === '' ||
12911286
trim($rowData['custom_options']) === $this->_productEntity->getEmptyAttributeValueConstant()
12921287
)
@@ -2098,6 +2093,7 @@ protected function _parseCustomOptions($rowData)
20982093
$optionValueParams = explode($this->_productEntity->getMultipleValueSeparator(), $optionValue);
20992094
foreach ($optionValueParams as $nameAndValue) {
21002095
$nameAndValue = explode('=', $nameAndValue);
2096+
// @phpstan-ignore-next-line
21012097
if (!empty($nameAndValue)) {
21022098
$value = isset($nameAndValue[1]) ? $nameAndValue[1] : '';
21032099
$value = trim($value);

app/code/Magento/Checkout/view/frontend/templates/cart/coupon.phtml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
*/
1010

1111
// We should use strlen function because coupon code could be "0", converted to bool will lead to false
12-
$hasCouponCode = (bool) strlen($block->getCouponCode());
12+
$hasCouponCode = (bool) ($block->getCouponCode() ? strlen($block->getCouponCode()) : '');
1313
?>
1414
<div class="block discount"
1515
id="block-discount"
16-
data-mage-init='{"collapsible":{"active": <?= $hasCouponCode ? 'true' : 'false' ?>, "openedState": "active", "saveState": false}}'
16+
data-mage-init='{"collapsible":{"active": <?= $hasCouponCode ? 'true' : 'false' ?>,
17+
"openedState": "active", "saveState": false}}'
1718
>
1819
<div class="title" data-role="title">
19-
<strong id="block-discount-heading" role="heading" aria-level="2"><?= $block->escapeHtml(__('Apply Discount Code')) ?></strong>
20+
<strong id="block-discount-heading" role="heading" aria-level="2">
21+
<?= $block->escapeHtml(__('Apply Discount Code')) ?>
22+
</strong>
2023
</div>
2124
<div class="content" data-role="content" aria-labelledby="block-discount-heading">
2225
<form id="discount-coupon-form"
@@ -29,35 +32,41 @@ $hasCouponCode = (bool) strlen($block->getCouponCode());
2932
<div class="fieldset coupon<?= $hasCouponCode ? ' applied' : '' ?>">
3033
<input type="hidden" name="remove" id="remove-coupon" value="0" />
3134
<div class="field">
32-
<label for="coupon_code" class="label"><span><?= $block->escapeHtml(__('Enter discount code')) ?></span></label>
35+
<label for="coupon_code" class="label">
36+
<span><?= $block->escapeHtml(__('Enter discount code')) ?></span>
37+
</label>
3338
<div class="control">
3439
<input type="text"
3540
class="input-text"
3641
id="coupon_code"
3742
name="coupon_code"
3843
value="<?= $block->escapeHtmlAttr($block->getCouponCode()) ?>"
3944
placeholder="<?= $block->escapeHtmlAttr(__('Enter discount code')) ?>"
40-
<?php if ($hasCouponCode) :?>
45+
<?php if ($hasCouponCode): ?>
4146
disabled="disabled"
4247
<?php endif; ?>
4348
/>
4449
</div>
4550
</div>
4651
<div class="actions-toolbar">
47-
<?php if (!$hasCouponCode) :?>
52+
<?php if (!$hasCouponCode): ?>
4853
<div class="primary">
49-
<button class="action apply primary" type="button" value="<?= $block->escapeHtmlAttr(__('Apply Discount')) ?>">
54+
<button class="action apply primary" type="button"
55+
value="<?= $block->escapeHtmlAttr(__('Apply Discount')) ?>">
5056
<span><?= $block->escapeHtml(__('Apply Discount')) ?></span>
5157
</button>
5258
</div>
53-
<?php else :?>
59+
<?php else: ?>
5460
<div class="primary">
55-
<button type="button" class="action cancel primary" value="<?= $block->escapeHtmlAttr(__('Cancel Coupon')) ?>"><span><?= $block->escapeHtml(__('Cancel Coupon')) ?></span></button>
61+
<button type="button" class="action cancel primary"
62+
value="<?= $block->escapeHtmlAttr(__('Cancel Coupon')) ?>">
63+
<span><?= $block->escapeHtml(__('Cancel Coupon')) ?></span>
64+
</button>
5665
</div>
5766
<?php endif; ?>
5867
</div>
5968
</div>
60-
<?php if (!$hasCouponCode) : ?>
69+
<?php if (!$hasCouponCode): ?>
6170
<?= /* @noEscape */ $block->getChildHtml('captcha') ?>
6271
<?php endif; ?>
6372
</form>

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
*/
2525
class Address extends AbstractCustomer
2626
{
27-
/**#@+
28-
* Attribute collection name
27+
/**
28+
* Customer Address EAV additional attribute collection name
2929
*/
3030
const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection::class;
3131

32-
/**#@-*/
33-
34-
/**#@+
32+
/**
3533
* Permanent column names
3634
*
3735
* Names that begins with underscore is not an attribute.
@@ -41,9 +39,7 @@ class Address extends AbstractCustomer
4139

4240
const COLUMN_ADDRESS_ID = '_entity_id';
4341

44-
/**#@-*/
45-
46-
/**#@+
42+
/**
4743
* Required column names
4844
*/
4945
const COLUMN_REGION = 'region';
@@ -52,20 +48,16 @@ class Address extends AbstractCustomer
5248

5349
const COLUMN_POSTCODE = 'postcode';
5450

55-
/**#@-*/
56-
5751
const COLUMN_REGION_ID = 'region_id';
5852

59-
/**#@+
53+
/**
6054
* Particular columns that contains of customer default addresses
6155
*/
6256
const COLUMN_DEFAULT_BILLING = '_address_default_billing_';
6357

6458
const COLUMN_DEFAULT_SHIPPING = '_address_default_shipping_';
6559

66-
/**#@-*/
67-
68-
/**#@+
60+
/**
6961
* Error codes
7062
*/
7163
const ERROR_ADDRESS_ID_IS_EMPTY = 'addressIdIsEmpty';
@@ -76,9 +68,9 @@ class Address extends AbstractCustomer
7668

7769
const ERROR_DUPLICATE_PK = 'duplicateAddressId';
7870

79-
/**#@-*/
80-
81-
/**#@-*/
71+
/**
72+
* @var string[]
73+
*/
8274
protected static $_defaultAddressAttributeMapping = [
8375
self::COLUMN_DEFAULT_BILLING => 'default_billing',
8476
self::COLUMN_DEFAULT_SHIPPING => 'default_shipping',
@@ -152,8 +144,6 @@ class Address extends AbstractCustomer
152144
];
153145

154146
/**
155-
* Customer entity
156-
*
157147
* @var \Magento\Customer\Model\Customer
158148
*/
159149
protected $_customerEntity;
@@ -216,16 +206,12 @@ class Address extends AbstractCustomer
216206
protected $dateTime;
217207

218208
/**
219-
* Customer attributes
220-
*
221209
* @var string[]
222210
*/
223211
protected $_customerAttributes = [];
224212

225213
/**
226-
* Valid column names
227-
*
228-
* @array
214+
* @var string[]
229215
*/
230216
protected $validColumnNames = [
231217
"region_id",
@@ -644,7 +630,7 @@ protected function _prepareDataForUpdate(array $rowData): array
644630

645631
$value = $rowData[$attributeAlias];
646632

647-
if (!strlen($rowData[$attributeAlias])) {
633+
if ($rowData[$attributeAlias] === null || !strlen($rowData[$attributeAlias])) {
648634
if ($attributeParams['is_required']) {
649635
continue;
650636
}

0 commit comments

Comments
 (0)