Skip to content

Commit 7d75de2

Browse files
karyna-tandrewbess
authored andcommitted
magento#34505: fixes for php 8.1 compatibility
1 parent 2a1789f commit 7d75de2

File tree

11 files changed

+32
-32
lines changed

11 files changed

+32
-32
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Bundle\Model\Product\Price;
99
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Type;
1011
use Magento\Catalog\Pricing\Price as CatalogPrice;
1112
use Magento\Framework\Event\ManagerInterface;
1213
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
@@ -162,10 +163,10 @@ public function getAmount()
162163
if ($product->hasData($bundleSelectionKey)) {
163164
return $product->getData($bundleSelectionKey);
164165
}
165-
$value = $this->getValue();
166+
$value = (string) $this->getValue();
166167
if (!isset($this->amount[$value])) {
167168
$exclude = null;
168-
if ($this->getProduct()->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
169+
if ($this->getProduct()->getTypeId() === Type::TYPE_BUNDLE) {
169170
$exclude = $this->excludeAdjustment;
170171
}
171172
$this->amount[$value] = $this->calculator->getAmount(

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
abstract class AbstractType
2424
{
2525
/**
26-
* Common attributes cache
27-
*
2826
* @var array
2927
*/
3028
public static $commonAttributesCache = [];
@@ -149,8 +147,6 @@ abstract class AbstractType
149147
protected $metadataPool;
150148

151149
/**
152-
* Product entity link field
153-
*
154150
* @var string
155151
*/
156152
private $productEntityLinkField;
@@ -332,6 +328,7 @@ protected function attachAttributesById($attributeSetName, $attributeIds)
332328

333329
if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) {
334330
if (!isset(self::$commonAttributesCache[$attributeId])) {
331+
$defaultValue = $attribute->getDefaultValue();
335332
self::$commonAttributesCache[$attributeId] = [
336333
'id' => $attributeId,
337334
'code' => $attributeCode,
@@ -342,9 +339,8 @@ protected function attachAttributesById($attributeSetName, $attributeIds)
342339
'is_static' => $attribute->isStatic(),
343340
'apply_to' => $attribute->getApplyTo(),
344341
'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute),
345-
'default_value' => strlen(
346-
$attribute->getDefaultValue()
347-
) ? $attribute->getDefaultValue() : null,
342+
'default_value' => (is_string($defaultValue) && strlen($defaultValue)) ?
343+
$attribute->getDefaultValue() : null,
348344
'options' => $this->_entityModel->getAttributeOptions(
349345
$attribute,
350346
$this->_indexValueAttributes
@@ -597,6 +593,7 @@ public function saveData()
597593
protected function getMetadataPool()
598594
{
599595
if (!$this->metadataPool) {
596+
// phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
600597
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
601598
->get(\Magento\Framework\EntityManager\MetadataPool::class);
602599
}

app/code/Magento/Cms/Model/Block.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public function beforeSave()
107107
}
108108

109109
$needle = 'block_id="' . $this->getId() . '"';
110-
if (strstr($this->getContent(), (string) $needle) !== false) {
110+
$content = ($this->getContent() !== null) ? $this->getContent() : '';
111+
if (strpos($content, $needle) !== false) {
111112
throw new \Magento\Framework\Exception\LocalizedException(
112113
__('Make sure that static block content does not reference the block itself.')
113114
);
@@ -121,9 +122,9 @@ public function beforeSave()
121122
parent::beforeSave();
122123

123124
//Validating HTML content.
124-
if ($this->getContent() && $this->getContent() !== $this->getOrigData(self::CONTENT)) {
125+
if ($content && $content !== $this->getOrigData(self::CONTENT)) {
125126
try {
126-
$this->wysiwygValidator->validate($this->getContent());
127+
$this->wysiwygValidator->validate($content);
127128
} catch (ValidationException $exception) {
128129
throw new ValidationException(
129130
__('Content field contains restricted HTML elements. %1', $exception->getMessage()),

app/code/Magento/Downloadable/Helper/Catalog/Product/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getLinks(\Magento\Catalog\Model\Product\Configuration\Item\ItemI
6464
public function getLinksTitle($product)
6565
{
6666
$title = $product->getLinksTitle();
67-
if (strlen($title)) {
67+
if ($title !== null && strlen($title)) {
6868
return $title;
6969
}
7070
return $this->scopeConfig->getValue(

app/code/Magento/Payment/Block/Info/Instructions.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ class Instructions extends \Magento\Payment\Block\Info
3434
public function getInstructions()
3535
{
3636
if ($this->_instructions === null) {
37-
$this->_instructions = $this->getInfo()->getAdditionalInformation(
38-
'instructions'
39-
) ?: trim($this->getMethod()->getConfigData('instructions'));
37+
$this->_instructions = $this->getInfo()->getAdditionalInformation('instructions')
38+
?: trim($this->getMethod()->getConfigData('instructions') ?? '');
4039
}
4140
return $this->_instructions;
4241
}

app/code/Magento/Sales/Model/Order.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,16 +2037,19 @@ public function getCustomerName()
20372037
}
20382038

20392039
$customerName = '';
2040-
if ($this->isVisibleCustomerPrefix() && strlen($this->getCustomerPrefix())) {
2041-
$customerName .= $this->getCustomerPrefix() . ' ';
2040+
$prefix = $this->getCustomerPrefix();
2041+
if (($prefix !== null) && $this->isVisibleCustomerPrefix() && strlen($prefix)) {
2042+
$customerName .= $prefix . ' ';
20422043
}
20432044
$customerName .= $this->getCustomerFirstname();
2044-
if ($this->isVisibleCustomerMiddlename() && strlen($this->getCustomerMiddlename())) {
2045-
$customerName .= ' ' . $this->getCustomerMiddlename();
2045+
$middlename = $this->getCustomerMiddlename();
2046+
if (($middlename !== null) && $this->isVisibleCustomerMiddlename() && strlen($middlename)) {
2047+
$customerName .= ' ' . $middlename;
20462048
}
20472049
$customerName .= ' ' . $this->getCustomerLastname();
2048-
if ($this->isVisibleCustomerSuffix() && strlen($this->getCustomerSuffix())) {
2049-
$customerName .= ' ' . $this->getCustomerSuffix();
2050+
$suffix = $this->getCustomerSuffix();
2051+
if (($suffix !== null) && $this->isVisibleCustomerSuffix() && strlen($suffix)) {
2052+
$customerName .= ' ' . $suffix;
20502053
}
20512054

20522055
return $customerName;

lib/internal/Magento/Framework/Image/Adapter/Gd2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ private function imagecopymergeWithAlphaFix(
916916
return false;
917917
}
918918

919-
$transparency = 127 - (($pct*127)/100);
919+
$transparency = (int) (127 - (($pct * 127) / 100));
920920
if (false === imagefilter($tmpImg, IMG_FILTER_COLORIZE, 0, 0, 0, $transparency)) {
921921
return false;
922922
}

lib/internal/Magento/Framework/Pricing/Price/AbstractPrice.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ abstract public function getValue();
9999
*/
100100
public function getAmount()
101101
{
102-
if (!isset($this->amount[$this->getValue()])) {
103-
$this->amount[$this->getValue()] = $this->calculator->getAmount($this->getValue(), $this->getProduct());
102+
$valueKey = (string) $this->getValue();
103+
if (!isset($this->amount[$valueKey])) {
104+
$this->amount[$valueKey] = $this->calculator->getAmount($this->getValue(), $this->getProduct());
104105
}
105-
return $this->amount[$this->getValue()];
106+
return $this->amount[$valueKey];
106107
}
107108

108109
/**

lib/internal/Magento/Framework/Search/Dynamic/Algorithm/Auto.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ private function getRange($bucket, array $dimensions, EntityStorage $entityStora
8080
private function getMaxPriceInt(EntityStorage $entityStorage)
8181
{
8282
$aggregations = $this->dataProvider->getAggregations($entityStorage);
83-
$maxPrice = $aggregations['max'];
84-
$maxPrice = floor($maxPrice);
85-
86-
return $maxPrice;
83+
return ($aggregations['max'] !== null) ? floor($aggregations['max']) : 0;
8784
}
8885

8986
/**

setup/src/Magento/Setup/Console/Command/GenerateFixturesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function executeFixture(\Magento\Setup\Fixtures\Fixture $fixture, Output
167167
$startTime = microtime(true);
168168
$fixture->execute($output);
169169
$endTime = microtime(true);
170-
$resultTime = $endTime - $startTime;
170+
$resultTime = (int) ($endTime - $startTime);
171171
$output->writeln('<info> done in ' . gmdate('H:i:s', $resultTime) . '</info>');
172172
}
173173
}

setup/src/Magento/Setup/Model/BatchInsert.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ public function flush()
8686
$this->dataStorage->setSize($this->currentStorageIndex);
8787
}
8888

89+
$this->dataStorage->rewind();
8990
$this->getDbConnection()
9091
->insertArray(
9192
$this->insertIntoTable,
92-
array_keys(reset($this->dataStorage)),
93+
array_keys($this->dataStorage->current()),
9394
$this->dataStorage->toArray()
9495
);
9596

0 commit comments

Comments
 (0)