From 88b672f9eebbab3454cc49044d8b9092340ba7ae Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 13 Oct 2023 19:40:45 -0400 Subject: [PATCH] CRM/Contact - Refactor unnecessary uses of CRM_Utils_Array::value --- CRM/Contact/BAO/GroupNesting.php | 2 +- CRM/Contact/BAO/Query.php | 6 +++--- CRM/Contact/Form/Contact.php | 19 ++++++++----------- CRM/Contact/Form/Edit/Address.php | 2 +- .../Form/Inline/CommunicationPreferences.php | 2 +- CRM/Contact/Form/Relationship.php | 6 +++--- CRM/Contact/Form/Search.php | 2 +- CRM/Contact/Form/Search/Criteria.php | 2 +- CRM/Contact/Form/Task.php | 2 +- CRM/Contact/Form/Task/EmailTrait.php | 2 +- CRM/Contact/Form/Task/Label.php | 2 +- CRM/Contact/Page/View/Vcard.php | 8 ++++---- 12 files changed, 26 insertions(+), 29 deletions(-) diff --git a/CRM/Contact/BAO/GroupNesting.php b/CRM/Contact/BAO/GroupNesting.php index f480e44566..4e3f17cee7 100644 --- a/CRM/Contact/BAO/GroupNesting.php +++ b/CRM/Contact/BAO/GroupNesting.php @@ -27,7 +27,7 @@ class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting { */ public static function create($params) { $hook = empty($params['id']) ? 'create' : 'edit'; - CRM_Utils_Hook::pre($hook, 'GroupNesting', CRM_Utils_Array::value('id', $params), $params); + CRM_Utils_Hook::pre($hook, 'GroupNesting', $params['id'] ?? NULL, $params); $dao = new CRM_Contact_BAO_GroupNesting(); $dao->copyValues($params); if (empty($params['id'])) { diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 0969bc8bfc..6fb4936ad1 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4247,7 +4247,7 @@ WHERE $smartGroupClause if (!empty($relQill)) { $relQill .= ' OR '; } - $relQill .= CRM_Utils_Array::value($rel, $allRelationshipType); + $relQill .= $allRelationshipType[$rel] ?? ''; } $this->_qill[$grouping][] = 'Relationship Type(s) ' . $relQill . " ( " . implode(", ", $qillNames) . " )"; } @@ -6202,7 +6202,7 @@ AND displayRelType.is_active = 1 $pseudoOptions = CRM_Core_PseudoConstant::worldRegion(); } elseif ($daoName == 'CRM_Event_DAO_Event' && $fieldName == 'id') { - $checkPermission = CRM_Utils_Array::value('check_permission', $pseudoExtraParam, TRUE); + $checkPermission = $pseudoExtraParam['check_permission'] ?? TRUE; $pseudoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, $checkPermission, TRUE); } elseif ($fieldName == 'contribution_product_id') { @@ -6437,7 +6437,7 @@ AND displayRelType.is_active = 1 // is not declared for them. // @todo so far only integer fields are being handled. If we add string fields we need to look at // escaping. - $pseudoConstantMetadata = CRM_Utils_Array::value('pseudoconstant', $fieldSpec, FALSE); + $pseudoConstantMetadata = $fieldSpec['pseudoconstant'] ?? FALSE; if (!empty($pseudoConstantMetadata) ) { if (!empty($pseudoConstantMetadata['optionGroupName']) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index a016b17d3d..b10acd3ad6 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -501,10 +501,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { // make we require one primary block, CRM-5505 if ($updateMode) { if (!$hasPrimary) { - $hasPrimary = CRM_Utils_Array::value( - 'is_primary', - CRM_Utils_Array::value($instance, $defaults[$name]) - ); + $hasPrimary = !empty($defaults[$name][$instance]['is_primary']); } continue; } @@ -1060,7 +1057,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { if (array_key_exists('CommunicationPreferences', $this->_editOptions)) { // this is a chekbox, so mark false if we dont get a POST value - $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE); + $params['is_opt_out'] = $params['is_opt_out'] ?? FALSE; CRM_Utils_Array::formatArrayKeys($params['preferred_communication_method']); } @@ -1294,15 +1291,15 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { for ($i = 0; $i < count($contactLinks['rows']); $i++) { $row .= ' '; $row .= ' '; - $row .= CRM_Utils_Array::value('display_name', $contactLinks['rows'][$i]); + $row .= $contactLinks['rows'][$i]['display_name'] ?? ''; $row .= ' '; $row .= ' '; - $row .= CRM_Utils_Array::value('primary_email', $contactLinks['rows'][$i]); + $row .= $contactLinks['rows'][$i]['primary_email'] ?? ''; $row .= ' '; $row .= ' '; - $row .= CRM_Utils_Array::value('view', $contactLinks['rows'][$i]); - $row .= CRM_Utils_Array::value('edit', $contactLinks['rows'][$i]); - $row .= CRM_Utils_Array::value('merge', $contactLinks['rows'][$i]); + $row .= $contactLinks['rows'][$i]['view'] ?? ''; + $row .= $contactLinks['rows'][$i]['edit'] ?? ''; + $row .= $contactLinks['rows'][$i]['merge'] ?? ''; $row .= ' '; $row .= ' '; } @@ -1413,7 +1410,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { $streetAddress .= ' '; } } - $streetAddress .= CRM_Utils_Array::value($fld, $address); + $streetAddress .= $address[$fld] ?? ''; } $address['street_address'] = trim($streetAddress); $parseSuccess[$instance] = TRUE; diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php index 8b88bb49c2..4c82a7ff51 100644 --- a/CRM/Contact/Form/Edit/Address.php +++ b/CRM/Contact/Form/Edit/Address.php @@ -296,7 +296,7 @@ class CRM_Contact_Form_Edit_Address { $streetAddress .= ' '; } } - $streetAddress .= CRM_Utils_Array::value($fld, $address); + $streetAddress .= $address[$fld] ?? ''; } $streetAddress = trim($streetAddress); if (!empty($streetAddress)) { diff --git a/CRM/Contact/Form/Inline/CommunicationPreferences.php b/CRM/Contact/Form/Inline/CommunicationPreferences.php index 6452b0b02e..f65942b56f 100644 --- a/CRM/Contact/Form/Inline/CommunicationPreferences.php +++ b/CRM/Contact/Form/Inline/CommunicationPreferences.php @@ -65,7 +65,7 @@ class CRM_Contact_Form_Inline_CommunicationPreferences extends CRM_Contact_Form_ // Process / save communication preferences // this is a chekbox, so mark false if we dont get a POST value - $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE); + $params['is_opt_out'] = $params['is_opt_out'] ?? FALSE; $params['contact_type'] = $this->_contactType; $params['contact_id'] = $this->_contactId; diff --git a/CRM/Contact/Form/Relationship.php b/CRM/Contact/Form/Relationship.php index 46f69186b9..7001592c6b 100644 --- a/CRM/Contact/Form/Relationship.php +++ b/CRM/Contact/Form/Relationship.php @@ -489,7 +489,7 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { $jsData[$id] = array_filter(array_intersect_key($allRelationshipNames[$id], $whatWeWant)); // Add user-friendly placeholder foreach (['a', 'b'] as $x) { - $type = !empty($jsData[$id]["contact_sub_type_$x"]) ? $jsData[$id]["contact_sub_type_$x"] : CRM_Utils_Array::value("contact_type_$x", $jsData[$id]); + $type = !empty($jsData[$id]["contact_sub_type_$x"]) ? $jsData[$id]["contact_sub_type_$x"] : (CRM_Utils_Array::value("contact_type_$x", $jsData[$id])); $jsData[$id]["placeholder_$x"] = $type ? ts('- select %1 -', [strtolower($contactTypes[$type]['label'])]) : ts('- select contact -'); } } @@ -575,8 +575,8 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form { } // If this is a b_a relationship these form elements are flipped - $params['is_permission_a_b'] = CRM_Utils_Array::value("is_permission_{$a}_{$b}", $values, 0); - $params['is_permission_b_a'] = CRM_Utils_Array::value("is_permission_{$b}_{$a}", $values, 0); + $params['is_permission_a_b'] = $values["is_permission_{$a}_{$b}"] ?? 0; + $params['is_permission_b_a'] = $values["is_permission_{$b}_{$a}"] ?? 0; return [$params, $a]; } diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 575b3d38c2..e85d3ede3b 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -668,7 +668,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { } } $this->assign('id', - CRM_Utils_Array::value('uf_group_id', $this->_formValues) + $this->_formValues['uf_group_id'] ?? NULL ); $operator = CRM_Utils_Array::value('operator', $this->_formValues, CRM_Contact_BAO_Query::SEARCH_OPERATOR_AND); $this->set('queryOperator', $operator); diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index ac6b938203..99fa126a30 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -461,7 +461,7 @@ class CRM_Contact_Form_Search_Criteria { } if ($addressOptions['postal_code']) { - $attr = ['class' => 'six'] + (array) CRM_Utils_Array::value('postal_code', $attributes); + $attr = ['class' => 'six'] + ($attributes['postal_code'] ?? []); $form->addElement('text', 'postal_code_low', NULL, $attr + ['placeholder' => ts('From')]); $form->addElement('text', 'postal_code_high', NULL, $attr + ['placeholder' => ts('To')]); } diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 6d21f77a26..f7eb547968 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -262,7 +262,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $queryOperator = 'AND'; } $dao = $selector->contactIDQuery($params, $sortID, - CRM_Utils_Array::value('display_relationship_type', $fv), + $fv['display_relationship_type'] ?? NULL, $queryOperator ); diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 1755bbc232..3a97596024 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -384,7 +384,7 @@ trait CRM_Contact_Form_Task_EmailTrait { $cc, $bcc, $additionalDetails, - CRM_Utils_Array::value('campaign_id', $formValues), + $formValues['campaign_id'] ?? NULL, $this->getCaseID() ); diff --git a/CRM/Contact/Form/Task/Label.php b/CRM/Contact/Form/Task/Label.php index e303d62dd1..0b84559684 100644 --- a/CRM/Contact/Form/Task/Label.php +++ b/CRM/Contact/Form/Task/Label.php @@ -250,7 +250,7 @@ class CRM_Contact_Form_Task_Label extends CRM_Contact_Form_Task { if (!empty($fv['location_type_id'])) { foreach ($valuesothers as $vals) { if (($vals['location_type_id'] ?? NULL) == - CRM_Utils_Array::value('location_type_id', $fv) + ($fv['location_type_id'] ?? NULL) ) { foreach ($vals as $k => $v) { if (in_array($k, [ diff --git a/CRM/Contact/Page/View/Vcard.php b/CRM/Contact/Page/View/Vcard.php index 9d98552cf3..29ff266df6 100644 --- a/CRM/Contact/Page/View/Vcard.php +++ b/CRM/Contact/Page/View/Vcard.php @@ -45,10 +45,10 @@ class CRM_Contact_Page_View_Vcard extends CRM_Contact_Page_View { if ($defaults['contact_type'] == 'Individual') { $vcard->setName(CRM_Utils_Array::value('last_name', $defaults), - CRM_Utils_Array::value('first_name', $defaults), - CRM_Utils_Array::value('middle_name', $defaults), - CRM_Utils_Array::value('prefix', $defaults), - CRM_Utils_Array::value('suffix', $defaults) + $defaults['first_name'] ?? NULL, + $defaults['middle_name'] ?? NULL, + $defaults['prefix'] ?? NULL, + $defaults['suffix'] ?? NULL ); $organizationName = $defaults['organization_name'] ?? NULL; if ($organizationName !== NULL) { -- 2.25.1