From 501f6873c6b4d4d131ea020bd2fafa392e78a26e Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Mon, 14 Aug 2023 15:14:43 +0200 Subject: [PATCH] - refactoring --- src/ArrayComparator.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/ArrayComparator.php b/src/ArrayComparator.php index 723c7bf8..33147979 100644 --- a/src/ArrayComparator.php +++ b/src/ArrayComparator.php @@ -9,6 +9,7 @@ */ namespace SebastianBergmann\Comparator; +use function array_is_list; use function array_key_exists; use function assert; use function is_array; @@ -128,7 +129,7 @@ private function indent(string $lines): string private function canonicalize(array &$array): void { - if ($this->isIndexedArray($array)) { + if (array_is_list($array)) { sort($array); } else { ksort($array); @@ -140,18 +141,4 @@ private function canonicalize(array &$array): void } } } - - private function isIndexedArray(array $array): bool - { - $expectedKey = 0; - - foreach ($array as $key => $value) { - if ($key !== $expectedKey) { - return false; - } - $expectedKey++; - } - - return true; - } }