Skip to content

Commit e02683b

Browse files
committed
fixes for php 8.1 compatibility
1 parent 0af0fba commit e02683b

File tree

16 files changed

+47
-35
lines changed

16 files changed

+47
-35
lines changed

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ protected function getImageFile()
787787
*/
788788
protected function parseSize($string)
789789
{
790-
$size = explode('x', strtolower($string));
790+
$size = $string ? explode('x', strtolower($string)) : [''];
791791
if (count($size) == 2) {
792792
return ['width' => $size[0] > 0 ? $size[0] : null, 'height' => $size[1] > 0 ? $size[1] : null];
793793
}

app/code/Magento/Catalog/Model/Category.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ public function getPathIds()
852852
{
853853
$ids = $this->getData('path_ids');
854854
if ($ids === null) {
855-
$ids = explode('/', $this->getPath());
855+
$ids = $this->getPath() ? explode('/', $this->getPath()) : [''];
856856
$this->setData('path_ids', $ids);
857857
}
858858
return $ids;
@@ -866,7 +866,7 @@ public function getPathIds()
866866
public function getLevel()
867867
{
868868
if (!$this->hasLevel()) {
869-
return count(explode('/', $this->getPath())) - 1;
869+
return $this->getPath() ? (count(explode('/', $this->getPath())) - 1) : 0;
870870
}
871871
return $this->getData(self::KEY_LEVEL);
872872
}

app/code/Magento/Catalog/Model/View/Asset/Image.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ public function getPath()
201201
*/
202202
public function getSourceFile()
203203
{
204-
return $this->mediaConfig->getBaseMediaPath()
205-
. DIRECTORY_SEPARATOR . ltrim($this->getFilePath(), DIRECTORY_SEPARATOR);
204+
$path = $this->getFilePath() ? ltrim($this->getFilePath(), DIRECTORY_SEPARATOR) : '';
205+
return $this->mediaConfig->getBaseMediaPath() . DIRECTORY_SEPARATOR . $path;
206206
}
207207

208208
/**

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ private function getAttributeValue($attributeId, $valueIds, $storeId)
561561
if (false !== $value) {
562562
$optionValue = $this->getAttributeOptionValue($attributeId, $valueIds, $storeId);
563563
if (null === $optionValue) {
564-
$value = $this->filterAttributeValue($value);
564+
$value = ($value !== null) ? $this->filterAttributeValue($value) : '';
565565
} else {
566566
$value = implode($this->separator, array_filter([$value, $optionValue]));
567567
}
@@ -581,7 +581,7 @@ private function getAttributeValue($attributeId, $valueIds, $storeId)
581581
private function getAttributeOptionValue($attributeId, $valueIds, $storeId)
582582
{
583583
$optionKey = $attributeId . '-' . $storeId;
584-
$attributeValueIds = explode(',', $valueIds);
584+
$attributeValueIds = ($valueIds !== null) ? explode(',', $valueIds) : [''];
585585
$attributeOptionValue = '';
586586
if (!array_key_exists($optionKey, $this->attributeOptions)
587587
) {
@@ -595,7 +595,7 @@ private function getAttributeOptionValue($attributeId, $valueIds, $storeId)
595595
$this->attributeOptions[$optionKey] = array_column($options, 'label', 'value');
596596
$this->attributeOptions[$optionKey] = array_map(
597597
function ($value) {
598-
return $this->filterAttributeValue($value);
598+
return ($value !== null) ? $this->filterAttributeValue($value) : '';
599599
},
600600
$this->attributeOptions[$optionKey]
601601
);
@@ -618,7 +618,7 @@ function ($value) {
618618
* @param string $value
619619
* @return string
620620
*/
621-
private function filterAttributeValue($value)
621+
private function filterAttributeValue(string $value)
622622
{
623623
return preg_replace('/\s+/iu', ' ', trim(strip_tags($value)));
624624
}

app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
115115
$resultTime = microtime(true) - $startTime;
116116

117117
$output->writeln(
118-
__('has been rebuilt successfully in %time', ['time' => gmdate('H:i:s', $resultTime)])
118+
__('has been rebuilt successfully in %time', ['time' => gmdate('H:i:s', (int) $resultTime)])
119119
);
120120
} catch (\Throwable $e) {
121121
$output->writeln('process error during indexation process:');

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,9 @@ public function setCountryId($countryId)
14521452
public function getStreet()
14531453
{
14541454
$street = $this->getData(self::KEY_STREET);
1455+
if (!$street) {
1456+
return [''];
1457+
}
14551458
return is_array($street) ? $street : explode("\n", $street);
14561459
}
14571460

app/code/Magento/Quote/Model/Quote/TotalsCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function collect(\Magento\Quote\Model\Quote $quote)
194194
protected function _validateCouponCode(\Magento\Quote\Model\Quote $quote)
195195
{
196196
$code = $quote->getData('coupon_code');
197-
if (strlen($code)) {
197+
if ($code !== null && strlen($code)) {
198198
$addressHasCoupon = false;
199199
$addresses = $quote->getAllAddresses();
200200
if (count($addresses) > 0) {

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -515,18 +515,8 @@ public function setShippingAmount($amount)
515515
*/
516516
public function setAdjustmentPositive($amount)
517517
{
518-
$amount = trim($amount);
519-
if (substr($amount, -1) == '%') {
520-
$amount = (double)substr($amount, 0, -1);
521-
$amount = $this->getOrder()->getGrandTotal() * $amount / 100;
522-
}
523-
524-
$amount = $this->priceCurrency->round($amount);
525-
$this->setData('base_adjustment_positive', $amount);
526-
527-
$amount = $this->priceCurrency->round($amount * $this->getOrder()->getBaseToOrderRate());
528-
$this->setData('adjustment_positive', $amount);
529-
return $this;
518+
$amount = trim((string) $amount);
519+
return $this->setAdjustmentAmount($amount, 'base_adjustment_positive', 'adjustment_positive');
530520
}
531521

532522
/**
@@ -537,17 +527,30 @@ public function setAdjustmentPositive($amount)
537527
*/
538528
public function setAdjustmentNegative($amount)
539529
{
540-
$amount = trim($amount);
530+
$amount = trim((string) $amount);
531+
return $this->setAdjustmentAmount($amount, 'base_adjustment_negative', 'adjustment_negative');
532+
}
533+
534+
/**
535+
* Set adjustment amount.
536+
*
537+
* @param string $amount
538+
* @param string $baseAdjustmentField
539+
* @param string $adjustmentField
540+
* @return $this
541+
*/
542+
private function setAdjustmentAmount(string $amount, string $baseAdjustmentField, string $adjustmentField): self
543+
{
541544
if (substr($amount, -1) == '%') {
542-
$amount = (double)substr($amount, 0, -1);
545+
$amount = (double) substr($amount, 0, -1);
543546
$amount = $this->getOrder()->getGrandTotal() * $amount / 100;
544547
}
545548

546549
$amount = $this->priceCurrency->round($amount);
547-
$this->setData('base_adjustment_negative', $amount);
550+
$this->setData($baseAdjustmentField, $amount);
548551

549552
$amount = $this->priceCurrency->round($amount * $this->getOrder()->getBaseToOrderRate());
550-
$this->setData('adjustment_negative', $amount);
553+
$this->setData($adjustmentField, $amount);
551554
return $this;
552555
}
553556

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function addDiscountDescription($address, $rule)
153153
if ($ruleLabel) {
154154
$label = $ruleLabel;
155155
} else {
156-
if (strlen($address->getCouponCode())) {
156+
if ($address->getCouponCode() !== null && strlen($address->getCouponCode())) {
157157
$label = $address->getCouponCode();
158158

159159
if ($rule->getDescription()) {

app/code/Magento/Tax/Model/ResourceModel/Calculation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected function _createSearchPostCodeTemplates($postcode, $exactPostcode = nu
233233
{
234234
// as needed, reduce the postcode to the correct length
235235
$len = $this->_taxData->getPostCodeSubStringLength();
236-
$postcode = substr($postcode, 0, $len);
236+
$postcode = ($postcode !== null) ? substr($postcode, 0, $len) : '';
237237

238238
// begin creating the search template array
239239
$strArr = [$postcode, $postcode . '*'];

0 commit comments

Comments
 (0)