CRM/Contact - Refactor unnecessary uses of CRM_Utils_Array::value
authorcolemanw <coleman@civicrm.org>
Fri, 13 Oct 2023 23:40:45 +0000 (19:40 -0400)
committercolemanw <coleman@civicrm.org>
Sat, 14 Oct 2023 03:17:06 +0000 (23:17 -0400)
12 files changed:
CRM/Contact/BAO/GroupNesting.php
CRM/Contact/BAO/Query.php
CRM/Contact/Form/Contact.php
CRM/Contact/Form/Edit/Address.php
CRM/Contact/Form/Inline/CommunicationPreferences.php
CRM/Contact/Form/Relationship.php
CRM/Contact/Form/Search.php
CRM/Contact/Form/Search/Criteria.php
CRM/Contact/Form/Task.php
CRM/Contact/Form/Task/EmailTrait.php
CRM/Contact/Form/Task/Label.php
CRM/Contact/Page/View/Vcard.php

index f480e44566e52a7ca8dd76449b8dd54bebd1f1de..4e3f17cee7fa56ca7a76310e036e184b582b906a 100644 (file)
@@ -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'])) {
index 0969bc8bfca313314565bca6ab39a742d4d6ce80..6fb4936ad15fd58ff9bd04e5ec3276c22294079c 100644 (file)
@@ -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'])
index a016b17d3d9df98fd0cabdfcd7a768430a233b2e..b10acd3ad6c62662b3b342eb0da02bcda3a2bebd 100644 (file)
@@ -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 .= '  <tr>   ';
           $row .= '    <td class="matching-contacts-name"> ';
-          $row .= CRM_Utils_Array::value('display_name', $contactLinks['rows'][$i]);
+          $row .= $contactLinks['rows'][$i]['display_name'] ?? '';
           $row .= '    </td>';
           $row .= '    <td class="matching-contacts-email"> ';
-          $row .= CRM_Utils_Array::value('primary_email', $contactLinks['rows'][$i]);
+          $row .= $contactLinks['rows'][$i]['primary_email'] ?? '';
           $row .= '    </td>';
           $row .= '    <td class="action-items"> ';
-          $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 .= '    </td>';
           $row .= '  </tr>   ';
         }
@@ -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;
index 8b88bb49c28605778e774640ff712f4f13b047f5..4c82a7ff5134d3060fc7fd644a48da974bccaae2 100644 (file)
@@ -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)) {
index 6452b0b02e4711b09fcb9447f6338defd1d3aea5..f65942b56ffeee3d628f8ebc86af4274cb28d92b 100644 (file)
@@ -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;
 
index 46f69186b9b1ce4b0998bcedf4859af7f6ed4fdf..7001592c6bc0cba6bf65fac1999b41dd2f315a34 100644 (file)
@@ -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];
   }
index 575b3d38c25e6c06a8ecaad9d48fee6b287ea04a..e85d3ede3b0970c67c116d74b6b89ca7c372ceea 100644 (file)
@@ -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);
index ac6b938203775b36aa90e833a7be0af9781d5322..99fa126a303abf4d3eee8703ea512c6bc3138fc7 100644 (file)
@@ -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')]);
       }
index 6d21f77a261ea639b66229ff1d1f69d36cbaf13d..f7eb5479687bd4012d02c74f1fdc64601e3139cd 100644 (file)
@@ -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
     );
 
index 1755bbc2327fc4e39b31b4874d94189993b3bcd3..3a97596024e4c3c58b721467d2b02ad5e2865271 100644 (file)
@@ -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()
     );
 
index e303d62dd13f9446be49eb7ef26a04bc9c30e70b..0b8455968456bd85a563f64a90f709135745bf4b 100644 (file)
@@ -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, [
index 9d98552cf35c053ac6d1dd35210fbd615588cb99..29ff266df677562a681b7254713952f7197226e5 100644 (file)
@@ -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) {