From b47d919ce66f253ba99f23f6d98d258e2381754c Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 8 Dec 2023 09:44:27 +0900 Subject: [PATCH 1/2] fix: TypeError in strict mode --- system/Helpers/Array/ArrayHelper.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/system/Helpers/Array/ArrayHelper.php b/system/Helpers/Array/ArrayHelper.php index d47ae94c5279..cadac28d6c29 100644 --- a/system/Helpers/Array/ArrayHelper.php +++ b/system/Helpers/Array/ArrayHelper.php @@ -306,16 +306,17 @@ public static function recursiveCount(array $array, int $counter = 0): int * Sorts array values in natural order * If the value is an array, you need to specify the $sortByIndex of the key to sort * - * @param int|string|null $sortByIndex + * @param list|string> $array + * @param int|string|null $sortByIndex */ public static function sortValuesByNatural(array &$array, $sortByIndex = null): bool { return usort($array, static function ($currentValue, $nextValue) use ($sortByIndex) { if ($sortByIndex !== null) { - return strnatcmp($currentValue[$sortByIndex], $nextValue[$sortByIndex]); + return strnatcmp((string) $currentValue[$sortByIndex], (string) $nextValue[$sortByIndex]); } - return strnatcmp($currentValue, $nextValue); + return strnatcmp((string) $currentValue, (string) $nextValue); }); } } From 29e6f76c1d359b3eb8ae3c0f2ae5b70efdcafe6b Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 8 Dec 2023 09:49:02 +0900 Subject: [PATCH 2/2] test: add `declare(strict_types=1)` --- .../system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php b/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php index 312eb0853c9d..861d6ede713f 100644 --- a/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php +++ b/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php @@ -1,5 +1,7 @@