Skip to content

Commit 3d4095f

Browse files
authored
Merge pull request #7291 from magento-trigger/ph-delivery
[Platform Health] Updates for PHP8.1
2 parents 26edafb + fc76974 commit 3d4095f

File tree

14 files changed

+87
-59
lines changed

14 files changed

+87
-59
lines changed

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

Lines changed: 6 additions & 5 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;
@@ -25,16 +26,14 @@ class BundleSelectionPrice extends AbstractPrice
2526
/**
2627
* Price model code
2728
*/
28-
const PRICE_CODE = 'bundle_selection';
29+
public const PRICE_CODE = 'bundle_selection';
2930

3031
/**
3132
* @var \Magento\Catalog\Model\Product
3233
*/
3334
protected $bundleProduct;
3435

3536
/**
36-
* Event manager
37-
*
3837
* @var \Magento\Framework\Event\ManagerInterface
3938
*/
4039
protected $eventManager;
@@ -162,10 +161,10 @@ public function getAmount()
162161
if ($product->hasData($bundleSelectionKey)) {
163162
return $product->getData($bundleSelectionKey);
164163
}
165-
$value = $this->getValue();
164+
$value = (string) $this->getValue();
166165
if (!isset($this->amount[$value])) {
167166
$exclude = null;
168-
if ($this->getProduct()->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
167+
if ($this->getProduct()->getTypeId() === Type::TYPE_BUNDLE) {
169168
$exclude = $this->excludeAdjustment;
170169
}
171170
$this->amount[$value] = $this->calculator->getAmount(
@@ -180,6 +179,8 @@ public function getAmount()
180179
}
181180

182181
/**
182+
* Returns the bundle product.
183+
*
183184
* @return SaleableInterface
184185
*/
185186
public function getProduct()

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: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class Block extends AbstractModel implements BlockInterface, IdentityInterface
2929
/**
3030
* CMS block cache tag
3131
*/
32-
const CACHE_TAG = 'cms_b';
32+
public const CACHE_TAG = 'cms_b';
3333

3434
/**#@+
3535
* Block's statuses
3636
*/
37-
const STATUS_ENABLED = 1;
38-
const STATUS_DISABLED = 0;
37+
public const STATUS_ENABLED = 1;
38+
public const STATUS_DISABLED = 0;
3939

40-
/**#@-*/
41-
42-
/**#@-*/
40+
/**
41+
* @var string
42+
*/
4343
protected $_cacheTag = self::CACHE_TAG;
4444

4545
/**
@@ -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/GraphQl/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"magento/module-webapi": "*",
1010
"magento/module-new-relic-reporting": "*",
1111
"magento/module-authorization": "*",
12-
"webonyx/graphql-php": "~14.9.0"
12+
"webonyx/graphql-php": "~14.11.3"
1313
},
1414
"suggest": {
1515
"magento/module-graph-ql-cache": "*"

app/code/Magento/GroupedProduct/Test/Unit/Pricing/Price/ConfiguredPriceTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ public function testGetAmount()
219219
{
220220
$resultPrice = rand(1, 9);
221221

222-
$this->price->expects($this->exactly(4))
223-
->method('getValue')
222+
$this->price->method('getValue')
224223
->willReturn($resultPrice);
225224

226225
$this->priceInfo->expects($this->once())

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ class Instructions extends \Magento\Payment\Block\Info
2626
protected $_template = 'Magento_Payment::info/instructions.phtml';
2727

2828
/**
29-
* Get instructions text from order payment
30-
* (or from config, if instructions are missed in payment)
29+
* Get instructions text from order payment (or from config, if instructions are missed in payment).
3130
*
3231
* @return string
3332
*/
3433
public function getInstructions()
3534
{
3635
if ($this->_instructions === null) {
37-
$this->_instructions = $this->getInfo()->getAdditionalInformation(
38-
'instructions'
39-
) ?: trim($this->getMethod()->getConfigData('instructions'));
36+
$additionalInstructions = $this->getInfo()->getAdditionalInformation('instructions');
37+
if ($additionalInstructions) {
38+
$this->_instructions = $additionalInstructions;
39+
return $this->_instructions;
40+
}
41+
42+
$instructions = $this->getMethod()->getConfigData('instructions');
43+
$this->_instructions = $instructions !== null ? trim($instructions) : '';
4044
}
4145
return $this->_instructions;
4246
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,7 @@ public function getRelatedObjects()
20292029
* Get customer name
20302030
*
20312031
* @return string
2032+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
20322033
*/
20332034
public function getCustomerName()
20342035
{
@@ -2037,16 +2038,19 @@ public function getCustomerName()
20372038
}
20382039

20392040
$customerName = '';
2040-
if ($this->isVisibleCustomerPrefix() && strlen($this->getCustomerPrefix())) {
2041-
$customerName .= $this->getCustomerPrefix() . ' ';
2041+
$prefix = $this->getCustomerPrefix();
2042+
if ($prefix !== null && $this->isVisibleCustomerPrefix() && strlen($prefix)) {
2043+
$customerName .= $prefix . ' ';
20422044
}
20432045
$customerName .= $this->getCustomerFirstname();
2044-
if ($this->isVisibleCustomerMiddlename() && strlen($this->getCustomerMiddlename())) {
2045-
$customerName .= ' ' . $this->getCustomerMiddlename();
2046+
$middlename = $this->getCustomerMiddlename();
2047+
if ($middlename !== null && $this->isVisibleCustomerMiddlename() && strlen($middlename)) {
2048+
$customerName .= ' ' . $middlename;
20462049
}
20472050
$customerName .= ' ' . $this->getCustomerLastname();
2048-
if ($this->isVisibleCustomerSuffix() && strlen($this->getCustomerSuffix())) {
2049-
$customerName .= ' ' . $this->getCustomerSuffix();
2051+
$suffix = $this->getCustomerSuffix();
2052+
if ($suffix !== null && $this->isVisibleCustomerSuffix() && strlen($suffix)) {
2053+
$customerName .= ' ' . $suffix;
20502054
}
20512055

20522056
return $customerName;

app/code/Magento/Sales/Test/Unit/Model/OrderTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ public function testCanInvoice()
401401
public function testGetCustomerName(array $expectedData)
402402
{
403403
$this->order->setCustomerFirstname($expectedData['first_name']);
404+
$this->order->setCustomerMiddlename($expectedData['middle_name']);
404405
$this->order->setCustomerSuffix($expectedData['customer_suffix']);
405406
$this->order->setCustomerPrefix($expectedData['customer_prefix']);
406407
$this->scopeConfigMock->expects($this->exactly($expectedData['invocation']))
@@ -420,6 +421,7 @@ public function customerNameProvider()
420421
[
421422
'first_name' => null,
422423
'invocation' => 0,
424+
'middle_name' => null,
423425
'expected_name' => 'Guest',
424426
'customer_suffix' => 'smith',
425427
'customer_prefix' => 'mr.'
@@ -428,11 +430,22 @@ public function customerNameProvider()
428430
[
429431
[
430432
'first_name' => 'Smith',
431-
'invocation' => 1,
433+
'invocation' => 0,
434+
'middle_name' => null,
432435
'expected_name' => 'mr. Smith Carl',
433436
'customer_suffix' => 'Carl',
434437
'customer_prefix' => 'mr.'
435438
]
439+
],
440+
[
441+
[
442+
'first_name' => 'John',
443+
'invocation' => 1,
444+
'middle_name' => 'Middle',
445+
'expected_name' => 'mr. John Middle Carl',
446+
'customer_suffix' => 'Carl',
447+
'customer_prefix' => 'mr.'
448+
]
436449
]
437450
];
438451
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ private function imagecopymergeWithAlphaFix(
947947
return false;
948948
}
949949

950-
$transparency = 127 - (($pct*127)/100);
950+
$transparency = (int) (127 - (($pct * 127) / 100));
951951
if (false === imagefilter($tmpImg, IMG_FILTER_COLORIZE, 0, 0, 0, $transparency)) {
952952
return false;
953953
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class AbstractPrice implements PriceInterface
2424
/**
2525
* Default price type
2626
*/
27-
const PRICE_CODE = 'abstract_price';
27+
public const PRICE_CODE = 'abstract_price';
2828

2929
/**
3030
* @var AmountInterface[]
@@ -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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(DataProviderInterface $dataProvider, OptionsInterfac
3434
}
3535

3636
/**
37-
* {@inheritdoc}
37+
* @inheritdoc
3838
*/
3939
public function getItems(
4040
BucketInterface $bucket,
@@ -53,6 +53,8 @@ public function getItems(
5353
}
5454

5555
/**
56+
* Returns price range.
57+
*
5658
* @param BucketInterface $bucket
5759
* @param array $dimensions
5860
* @param EntityStorage $entityStorage
@@ -80,13 +82,12 @@ private function getRange($bucket, array $dimensions, EntityStorage $entityStora
8082
private function getMaxPriceInt(EntityStorage $entityStorage)
8183
{
8284
$aggregations = $this->dataProvider->getAggregations($entityStorage);
83-
$maxPrice = $aggregations['max'];
84-
$maxPrice = floor($maxPrice);
85-
86-
return $maxPrice;
85+
return ($aggregations['max'] !== null) ? floor($aggregations['max']) : 0;
8786
}
8887

8988
/**
89+
* Return Minimal range power.
90+
*
9091
* @return int
9192
*/
9293
private function getMinRangePower()

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
*/
2222
class GenerateFixturesCommand extends Command
2323
{
24-
/**
25-
* Profile argument
26-
*/
27-
const PROFILE_ARGUMENT = 'profile';
24+
public const PROFILE_ARGUMENT = 'profile';
2825

29-
const SKIP_REINDEX_OPTION = 'skip-reindex';
26+
public const SKIP_REINDEX_OPTION = 'skip-reindex';
3027

3128
/**
3229
* @var FixtureModel
@@ -43,7 +40,7 @@ public function __construct(FixtureModel $fixtureModel)
4340
}
4441

4542
/**
46-
* {@inheritdoc}
43+
* @inheritdoc
4744
*/
4845
protected function configure()
4946
{
@@ -66,7 +63,7 @@ protected function configure()
6663
}
6764

6865
/**
69-
* {@inheritdoc}
66+
* @inheritdoc
7067
*/
7168
protected function execute(InputInterface $input, OutputInterface $output)
7269
{
@@ -158,6 +155,8 @@ private function clearChangelog()
158155
}
159156

160157
/**
158+
* Executes fixture and output the execution time.
159+
*
161160
* @param \Magento\Setup\Fixtures\Fixture $fixture
162161
* @param OutputInterface $output
163162
*/
@@ -167,7 +166,7 @@ private function executeFixture(\Magento\Setup\Fixtures\Fixture $fixture, Output
167166
$startTime = microtime(true);
168167
$fixture->execute($output);
169168
$endTime = microtime(true);
170-
$resultTime = $endTime - $startTime;
169+
$resultTime = (int) ($endTime - $startTime);
171170
$output->writeln('<info> done in ' . gmdate('H:i:s', $resultTime) . '</info>');
172171
}
173172
}

0 commit comments

Comments
 (0)