From f062e02d0596f517da32389165005aaa71cb6ae6 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 1 Feb 2021 14:40:17 +1300 Subject: [PATCH] [REF] do not needlessly pass as reference, enforce valid param --- CRM/Utils/Array.php | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 5ecdb554d5..ec6ecffd2b 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -61,20 +61,17 @@ class CRM_Utils_Array { * @return mixed * The value of the key, or null if the key is not found. */ - public static function retrieveValueRecursive(&$params, $key) { - if (!is_array($params)) { - return NULL; - } - elseif ($value = CRM_Utils_Array::value($key, $params)) { - return $value; + public static function retrieveValueRecursive(array $params, string $key) { + if (isset($params[$key])) { + return $params[$key]; } - else { - foreach ($params as $subParam) { - if (is_array($subParam) && - $value = self::retrieveValueRecursive($subParam, $key) - ) { - return $value; - } + foreach ($params as $subParam) { + if (is_array($subParam) && + // @todo - this will mishandle values like 0 and false + // but it's a little scary to fix. + $value = self::retrieveValueRecursive($subParam, $key) + ) { + return $value; } } return NULL; -- 2.25.1