From 93f36095d063d46a98d689a347be8f8e9374b3ba Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 7 Oct 2022 19:58:39 +0900 Subject: [PATCH] refactor: make if conditions simple --- system/Helpers/array_helper.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/system/Helpers/array_helper.php b/system/Helpers/array_helper.php index e4408bc60368..9b88cc2a0e0f 100644 --- a/system/Helpers/array_helper.php +++ b/system/Helpers/array_helper.php @@ -45,11 +45,15 @@ function dot_array_search(string $index, array $array) */ function _array_search_dot(array $indexes, array $array) { + // If index is empty, returns null. + if ($indexes === []) { + return null; + } + // Grab the current index - $currentIndex = $indexes ? array_shift($indexes) : null; - $intCurrentIndex = (int) $currentIndex; + $currentIndex = array_shift($indexes); - if (empty($currentIndex) && $intCurrentIndex !== 0 || (! isset($array[$currentIndex]) && $currentIndex !== '*')) { + if (! isset($array[$currentIndex]) && $currentIndex !== '*') { return null; }