Skip to content

Commit 282b23b

Browse files
committed
Merge remote-tracking branch 'SilinMykola/deprecations-php-8.1-compatibility-fixes' into ph-delivery
2 parents 6352973 + 82c06be commit 282b23b

File tree

12 files changed

+103
-156
lines changed

12 files changed

+103
-156
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Flat/AbstractAction.php

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\DB\Adapter\AdapterInterface;
1515
use Magento\Framework\DB\Ddl\Table;
1616
use Magento\Framework\EntityManager\EntityMetadata;
17+
use Magento\Framework\EntityManager\MetadataPool;
1718
use Magento\Store\Model\Store;
1819
use Magento\Store\Model\StoreManagerInterface;
1920

@@ -27,11 +28,9 @@ class AbstractAction
2728
/**
2829
* Suffix for table to show it is temporary
2930
*/
30-
const TEMPORARY_TABLE_SUFFIX = '_tmp';
31+
public const TEMPORARY_TABLE_SUFFIX = '_tmp';
3132

3233
/**
33-
* Attribute codes
34-
*
3534
* @var array
3635
*/
3736
protected $attributeCodes;
@@ -77,20 +76,33 @@ class AbstractAction
7776
*/
7877
protected $skipStaticColumns = [];
7978

79+
/**
80+
* @var SkipStaticColumnsProvider
81+
*/
82+
private $skipStaticColumnsProvider;
83+
8084
/**
8185
* @param ResourceConnection $resource
8286
* @param StoreManagerInterface $storeManager
8387
* @param Helper $resourceHelper
88+
* @param MetadataPool|null $metadataPool
89+
* @param SkipStaticColumnsProvider|null $skipStaticColumnsProvider
8490
*/
8591
public function __construct(
8692
ResourceConnection $resource,
8793
StoreManagerInterface $storeManager,
88-
Helper $resourceHelper
94+
Helper $resourceHelper,
95+
MetadataPool $metadataPool = null,
96+
SkipStaticColumnsProvider $skipStaticColumnsProvider = null
8997
) {
9098
$this->resource = $resource;
9199
$this->connection = $resource->getConnection();
92100
$this->storeManager = $storeManager;
93101
$this->resourceHelper = $resourceHelper;
102+
$metadataPool = $metadataPool ?? ObjectManager::getInstance()->get(MetadataPool::class);
103+
$this->categoryMetadata = $metadataPool->getMetadata(CategoryInterface::class);
104+
$this->skipStaticColumnsProvider = $skipStaticColumnsProvider
105+
?? ObjectManager::getInstance()->get(SkipStaticColumnsProvider::class);
94106
$this->columns = array_merge($this->getStaticColumns(), $this->getEavColumns());
95107
}
96108

@@ -213,7 +225,7 @@ protected function getStaticColumns()
213225
$isUnsigned = '';
214226
$options = null;
215227
$ddlType = $this->resourceHelper->getDdlTypeByColumnType($column['DATA_TYPE']);
216-
$column['DEFAULT'] = trim($column['DEFAULT'], "' ");
228+
$column['DEFAULT'] = $column['DEFAULT'] ? trim($column['DEFAULT'], "' ") : '';
217229
switch ($ddlType) {
218230
case Table::TYPE_SMALLINT:
219231
case Table::TYPE_INTEGER:
@@ -388,7 +400,7 @@ protected function getAttributeValues($entityIds, $storeId)
388400

389401
$attributes = $this->getAttributes();
390402
$attributesType = ['varchar', 'int', 'decimal', 'text', 'datetime'];
391-
$linkField = $this->getCategoryMetadata()->getLinkField();
403+
$linkField = $this->categoryMetadata->getLinkField();
392404
foreach ($attributesType as $type) {
393405
foreach ($this->getAttributeTypeValues($type, $entityIds, $storeId) as $row) {
394406
if (isset($row[$linkField], $row['attribute_id'])) {
@@ -414,7 +426,7 @@ protected function getAttributeValues($entityIds, $storeId)
414426
*/
415427
private function getLinkIds(array $entityIds)
416428
{
417-
$linkField = $this->getCategoryMetadata()->getLinkField();
429+
$linkField = $this->categoryMetadata->getLinkField();
418430
if ($linkField === 'entity_id') {
419431
return $entityIds;
420432
}
@@ -441,7 +453,7 @@ private function getLinkIds(array $entityIds)
441453
*/
442454
protected function getAttributeTypeValues($type, $entityIds, $storeId)
443455
{
444-
$linkField = $this->getCategoryMetadata()->getLinkField();
456+
$linkField = $this->categoryMetadata->getLinkField();
445457
$select = $this->connection->select()->from(
446458
[
447459
'def' => $this->connection->getTableName($this->getTableName('catalog_category_entity_' . $type)),
@@ -512,31 +524,14 @@ protected function getTableName($name)
512524
}
513525

514526
/**
515-
* Get category metadata instance.
516-
*
517-
* @return EntityMetadata
518-
*/
519-
private function getCategoryMetadata()
520-
{
521-
if (null === $this->categoryMetadata) {
522-
$metadataPool = ObjectManager::getInstance()
523-
->get(\Magento\Framework\EntityManager\MetadataPool::class);
524-
$this->categoryMetadata = $metadataPool->getMetadata(CategoryInterface::class);
525-
}
526-
return $this->categoryMetadata;
527-
}
528-
529-
/**
530-
* Get skip static columns instance.
527+
* Gets skipped static columns.
531528
*
532529
* @return array
533530
*/
534531
private function getSkipStaticColumns()
535532
{
536-
if (null === $this->skipStaticColumns) {
537-
$provider = ObjectManager::getInstance()
538-
->get(SkipStaticColumnsProvider::class);
539-
$this->skipStaticColumns = $provider->get();
533+
if ($this->skipStaticColumns === []) {
534+
$this->skipStaticColumns = $this->skipStaticColumnsProvider->get();
540535
}
541536
return $this->skipStaticColumns;
542537
}

app/code/Magento/Customer/Model/Data/Address.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Data Model implementing the Address interface
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -11,7 +9,7 @@
119
use \Magento\Framework\Api\AttributeValueFactory;
1210

1311
/**
14-
* Class Address
12+
* Class Address Data Model implementing the Address interface
1513
*
1614
*
1715
* @api
@@ -327,7 +325,10 @@ public function setCompany($company)
327325
*/
328326
public function setTelephone($telephone)
329327
{
330-
return $this->setData(self::TELEPHONE, trim($telephone));
328+
return $this->setData(
329+
self::TELEPHONE,
330+
is_string($telephone) && '' !== $telephone ? trim($telephone) : $telephone
331+
);
331332
}
332333

333334
/**

app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Options/Options.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ protected function _prepareOptionValues(
145145
) {
146146
$type = $attribute->getFrontendInput();
147147
if ($type === 'select' || $type === 'multiselect') {
148-
$defaultValues = explode(',', $attribute->getDefaultValue());
148+
$defaultValues = is_string($attribute->getDefaultValue())
149+
? explode(',', $attribute->getDefaultValue())
150+
: [];
149151
$inputType = $type === 'select' ? 'radio' : 'checkbox';
150152
} else {
151153
$defaultValues = [];

app/code/Magento/SalesRule/Model/Rule.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,26 @@ class Rule extends \Magento\Rule\Model\AbstractModel
7070
/**
7171
* Coupon types
7272
*/
73-
const COUPON_TYPE_NO_COUPON = 1;
73+
public const COUPON_TYPE_NO_COUPON = 1;
7474

75-
const COUPON_TYPE_SPECIFIC = 2;
75+
public const COUPON_TYPE_SPECIFIC = 2;
7676

77-
const COUPON_TYPE_AUTO = 3;
77+
public const COUPON_TYPE_AUTO = 3;
7878

7979
/**
8080
* Rule type actions
8181
*/
82-
const TO_PERCENT_ACTION = 'to_percent';
82+
public const TO_PERCENT_ACTION = 'to_percent';
8383

84-
const BY_PERCENT_ACTION = 'by_percent';
84+
public const BY_PERCENT_ACTION = 'by_percent';
8585

86-
const TO_FIXED_ACTION = 'to_fixed';
86+
public const TO_FIXED_ACTION = 'to_fixed';
8787

88-
const BY_FIXED_ACTION = 'by_fixed';
88+
public const BY_FIXED_ACTION = 'by_fixed';
8989

90-
const CART_FIXED_ACTION = 'cart_fixed';
90+
public const CART_FIXED_ACTION = 'cart_fixed';
9191

92-
const BUY_X_GET_Y_ACTION = 'buy_x_get_y';
92+
public const BUY_X_GET_Y_ACTION = 'buy_x_get_y';
9393

9494
/**
9595
* Store coupon code generator instance
@@ -285,7 +285,7 @@ public function loadCouponCode()
285285
*/
286286
public function afterSave()
287287
{
288-
$couponCode = trim($this->getCouponCode());
288+
$couponCode = is_string($this->getCouponCode()) ? trim($this->getCouponCode()) : '';
289289
if (strlen(
290290
$couponCode
291291
) && $this->getCouponType() == self::COUPON_TYPE_SPECIFIC && !$this->getUseAutoGeneration()

app/code/Magento/Security/Model/SecurityChecker/Frequency.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(
5656
}
5757

5858
/**
59-
* {@inheritdoc}
59+
* @inheritdoc
6060
*/
6161
public function check($securityEventType, $accountReference = null, $longIp = null)
6262
{
@@ -100,6 +100,6 @@ private function loadLastRecordCreationTimestamp($securityEventType, $accountRef
100100
/** @var \Magento\Security\Model\PasswordResetRequestEvent $record */
101101
$record = $collection->filterLastItem()->getFirstItem();
102102

103-
return (int) strtotime($record->getCreatedAt());
103+
return (int) strtotime($record->getCreatedAt() ?? '');
104104
}
105105
}

0 commit comments

Comments
 (0)