From dae3ecd876e3b5716ff6ccef9cf8e9f0cb95762a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 16 Sep 2024 18:16:41 +0200 Subject: [PATCH] MAG2-314 - PHP 8.2 and PHP 8.3 compatibility --- Model/Api/Payolution/PrivacyDeclaration.php | 2 +- Model/Entities/ApiLog.php | 4 ++-- Model/Entities/TransactionStatus.php | 4 ++-- Model/Methods/OnlineBankTransfer/Ideal.php | 2 +- Model/ResourceModel/TransactionStatus.php | 4 ++-- Test/Unit/Helper/ToolkitTest.php | 4 ++-- Test/Unit/Model/Entities/ApiLogTest.php | 2 +- Test/Unit/Model/Entities/TransactionStatusTest.php | 2 +- composer.json | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Model/Api/Payolution/PrivacyDeclaration.php b/Model/Api/Payolution/PrivacyDeclaration.php index 5753a9ba..a8d89c9c 100644 --- a/Model/Api/Payolution/PrivacyDeclaration.php +++ b/Model/Api/Payolution/PrivacyDeclaration.php @@ -183,7 +183,7 @@ public function getPayolutionAcceptanceText($sPaymentCode) } if (!$this->isUtf8($sPage)) { - $sPage = utf8_encode($sPage); + $sPage = mb_convert_encoding($sPage, 'UTF-8'); } return $sPage; diff --git a/Model/Entities/ApiLog.php b/Model/Entities/ApiLog.php index 7ecc03e8..097d28b5 100644 --- a/Model/Entities/ApiLog.php +++ b/Model/Entities/ApiLog.php @@ -83,7 +83,7 @@ protected function formatArray($aArray) { foreach ($aArray as $sKey => $mValue) { if (!$this->toolkitHelper->isUTF8($mValue)) { - $aArray[$sKey] = utf8_encode($mValue); + $aArray[$sKey] = mb_convert_encoding($mValue ?? '', 'UTF-8'); } } return $aArray; @@ -105,7 +105,7 @@ protected function getUnserializedArray($sKey, $blSort = false) $aRequest = unserialize($sRequest); } catch(\Exception $exc) { if ($this->toolkitHelper->isUTF8($sRequest)) { - $aRequest = unserialize(utf8_decode($sRequest)); + $aRequest = unserialize(mb_convert_encoding($sRequest ?? '', 'ISO-8859-1', 'UTF-8')); } } if (is_array($aRequest)) { diff --git a/Model/Entities/TransactionStatus.php b/Model/Entities/TransactionStatus.php index d4c26f5b..61d550d3 100644 --- a/Model/Entities/TransactionStatus.php +++ b/Model/Entities/TransactionStatus.php @@ -85,7 +85,7 @@ protected function formatArray($aArray) if (is_array($mValue)) { $aArray[$sKey] = $this->formatArray($mValue); } elseif (!$this->toolkitHelper->isUTF8($mValue)) { - $aArray[$sKey] = utf8_encode($mValue); + $aArray[$sKey] = mb_convert_encoding($mValue, 'UTF-8'); } } return $aArray; @@ -107,7 +107,7 @@ protected function getUnserializedArray($sKey, $blSort = false) $aRequest = unserialize($sRequest); } catch(\Exception $exc) { if ($this->toolkitHelper->isUTF8($sRequest)) { - $aRequest = unserialize(utf8_decode($sRequest)); + $aRequest = unserialize(mb_convert_encoding($sRequest, 'ISO-8859-1', 'UTF-8')); } } if (is_array($aRequest)) { diff --git a/Model/Methods/OnlineBankTransfer/Ideal.php b/Model/Methods/OnlineBankTransfer/Ideal.php index 84a8362f..9f6dbc16 100644 --- a/Model/Methods/OnlineBankTransfer/Ideal.php +++ b/Model/Methods/OnlineBankTransfer/Ideal.php @@ -123,7 +123,7 @@ public static function getBankGroups() foreach (self::$aBankGroups as $sKey => $sTitle) { $aReturn[] = [ 'id' => $sKey, - 'title' => utf8_encode($sTitle), + 'title' => mb_convert_encoding($sTitle, 'UTF-8'), ]; } diff --git a/Model/ResourceModel/TransactionStatus.php b/Model/ResourceModel/TransactionStatus.php index 31898b94..54a1022c 100644 --- a/Model/ResourceModel/TransactionStatus.php +++ b/Model/ResourceModel/TransactionStatus.php @@ -120,7 +120,7 @@ public function getParam($sKey, $sDefault = '') if (isset($this->request[$sKey])) { $sParam = $this->request[$sKey]; if (!$this->toolkitHelper->isUTF8($sParam)) { - $sParam = utf8_encode($sParam); + $sParam = mb_convert_encoding($sParam, 'UTF-8'); } return $sParam; } @@ -141,7 +141,7 @@ public function addTransactionLogEntry($aRequest, Order $oOrder = null, $blHasBe $sRawStatus = serialize($this->getRequest()); if (!$this->toolkitHelper->isUTF8($sRawStatus)) { - $sRawStatus = utf8_encode($sRawStatus); // needed for serializing the array + $sRawStatus = mb_convert_encoding($sRawStatus, 'UTF-8'); // needed for serializing the array } $sOrderId = $oOrder !== null ? $oOrder->getIncrementId() : ''; $this->getConnection()->insert( diff --git a/Test/Unit/Helper/ToolkitTest.php b/Test/Unit/Helper/ToolkitTest.php index cf3ebf43..2a40d434 100644 --- a/Test/Unit/Helper/ToolkitTest.php +++ b/Test/Unit/Helper/ToolkitTest.php @@ -218,11 +218,11 @@ public function testFormatNumber() public function testIsUTF8() { $input = 'not utf-8 - ä'; - $result = $this->toolkit->isUTF8(utf8_decode($input)); + $result = $this->toolkit->isUTF8(mb_convert_encoding($input, 'ISO-8859-1', 'UTF-8')); $this->assertFalse($result); $input = 'utf-8 äöü'; - $result = $this->toolkit->isUTF8(utf8_encode($input)); + $result = $this->toolkit->isUTF8(mb_convert_encoding($input, 'UTF-8')); $this->assertTrue($result); } diff --git a/Test/Unit/Model/Entities/ApiLogTest.php b/Test/Unit/Model/Entities/ApiLogTest.php index 49ca42fa..706e8b31 100644 --- a/Test/Unit/Model/Entities/ApiLogTest.php +++ b/Test/Unit/Model/Entities/ApiLogTest.php @@ -75,7 +75,7 @@ public function testGetRawRequestArray() public function testGetRawStatusArrayException() { $aStatus = ['test1' => html_entity_decode(" ")]; - $this->classToTest->setData('raw_request', utf8_encode(serialize($aStatus))); + $this->classToTest->setData('raw_request', mb_convert_encoding(serialize($aStatus), 'UTF-8')); $this->toolkitHelper->method('isUTF8')->willReturn(true); $result = $this->classToTest->getRawRequestArray(); diff --git a/Test/Unit/Model/Entities/TransactionStatusTest.php b/Test/Unit/Model/Entities/TransactionStatusTest.php index 717ba4e8..f3f0b6e6 100644 --- a/Test/Unit/Model/Entities/TransactionStatusTest.php +++ b/Test/Unit/Model/Entities/TransactionStatusTest.php @@ -74,7 +74,7 @@ public function testGetRawStatusArrayNotUtf8() public function testGetRawStatusArrayException() { $aStatus = ['test1' => html_entity_decode(" ")]; - $this->classToTest->setData('raw_status', utf8_encode(serialize($aStatus))); + $this->classToTest->setData('raw_status', mb_convert_encoding(serialize($aStatus), 'UTF-8')); $this->toolkitHelper->method('isUTF8')->willReturn(true); $result = $this->classToTest->getRawStatusArray(); diff --git a/composer.json b/composer.json index 089938e1..c1b0ec4d 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "email": "tech.support@payone.de" }, "require": { - "php": "~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0|~8.0.0|~8.1.0", + "php": "~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0|~8.0.0|~8.1.0|~8.2.0|~8.3.0", "magento/framework": "^100.0.0|^101.0.0|^102.0.0|^103.0.0" }, "repositories": [