Skip to content

Commit

Permalink
Merge pull request #19478 from eileenmcnaughton/ref
Browse files Browse the repository at this point in the history
[REF] do not needlessly pass as reference, enforce valid param
  • Loading branch information
colemanw authored Feb 23, 2021
2 parents a9f0c32 + f062e02 commit 8d3f19d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions CRM/Utils/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@ public static function value($key, $list, $default = NULL) {
* @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;
Expand Down

0 comments on commit 8d3f19d

Please sign in to comment.