Skip to content

Commit 31322c4

Browse files
kiatngsreichel
andauthored
Fixed null deprecation in UnserializeArray.php (OpenMage#4394)
* Fixed issue OpenMage#4352 null deprecation in UnserializeArray.php * Added @ to suppress warnings and notices * Suppress PHPMD ErrorControlOperator * Fix suppress PHPMD ErrorControlOperator * Update app/code/core/Mage/Core/Helper/UnserializeArray.php phpstan fix * Update app/code/core/Mage/Core/Helper/UnserializeArray.php Co-authored-by: Sven Reichel <[email protected]> * updated test result * sonar-1 --------- Co-authored-by: Sven Reichel <[email protected]>
1 parent e5feff0 commit 31322c4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

app/code/core/Mage/Core/Helper/UnserializeArray.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ class Mage_Core_Helper_UnserializeArray
2626
* @param string $str
2727
* @return array
2828
* @throws Exception
29+
* @SuppressWarnings("PHPMD.ErrorControlOperator")
2930
*/
3031
public function unserialize($str)
3132
{
3233
try {
33-
$result = unserialize($str, ['allowed_classes' => false]);
34+
$str = is_null($str) ? '' : $str;
35+
$result = @unserialize($str, ['allowed_classes' => false]);
3436
if ($result === false && $str !== serialize(false)) {
3537
throw new Exception('Error unserializing data.');
3638
}

tests/unit/Mage/Core/Helper/UnserializeArrayTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ public function testUnserialize($expectedTesult, $string): void
5050

5151
public function provideUnserialize(): Generator
5252
{
53+
$errorMessage = 'Error unserializing data.';
54+
5355
yield 'null' => [
54-
'Error unserializing data.',
56+
$errorMessage,
5557
null,
5658
];
5759
yield 'empty string' => [
58-
'Error unserializing data.',
60+
$errorMessage,
5961
'',
6062
];
6163
yield 'random string' => [
62-
'unserialize(): Error at offset 0 of 3 bytes',
64+
$errorMessage,
6365
'abc',
6466
];
6567
yield 'valid' => [

0 commit comments

Comments
 (0)