Skip to content

Commit

Permalink
refactor: extract convertToArray()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 31, 2023
1 parent 3d167be commit 60f2fa0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions system/Helpers/Array/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ final class ArrayHelper
* @return array|bool|int|object|string|null
*/
public static function dotSearch(string $index, array $array)
{
return self::arraySearchDot(self::convertToArray($index), $array);
}

private static function convertToArray(string $index)
{
// See https://regex101.com/r/44Ipql/1
$segments = preg_split(
Expand All @@ -34,9 +39,10 @@ public static function dotSearch(string $index, array $array)
PREG_SPLIT_NO_EMPTY
);

$segments = array_map(static fn ($key) => str_replace('\.', '.', $key), $segments);

return self::arraySearchDot($segments, $array);
return array_map(
static fn ($key) => str_replace('\.', '.', $key),
$segments
);
}

/**
Expand Down

0 comments on commit 60f2fa0

Please sign in to comment.