Skip to content

Commit

Permalink
- refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexndlm committed Aug 14, 2023
1 parent 5b1cbe3 commit 501f687
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/ArrayComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace SebastianBergmann\Comparator;

use function array_is_list;
use function array_key_exists;
use function assert;
use function is_array;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}

0 comments on commit 501f687

Please sign in to comment.