Cleanup uses of CRM_Utils_Array::value related to numbers
authorColeman Watts <coleman@civicrm.org>
Sun, 15 Mar 2020 00:20:06 +0000 (20:20 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 15 Mar 2020 00:34:39 +0000 (20:34 -0400)
Some manual cleanup around the areas of code where CRM_Utils_Array::value is used for a number defaulting to 0

16 files changed:
CRM/Activity/BAO/Activity.php
CRM/Admin/Page/AJAX.php
CRM/Contact/Form/Search/Criteria.php
CRM/Contact/Import/Form/DataSource.php
CRM/Contribute/BAO/ContributionRecur.php
CRM/Core/BAO/Block.php
CRM/Core/BAO/Dashboard.php
CRM/Core/Menu.php
CRM/Core/Smarty/plugins/function.crmKey.php
CRM/Event/Form/Participant.php
CRM/Utils/Chart.php
api/v3/Contact.php
api/v3/DashboardContact.php
api/v3/Job.php
api/v3/utils.php
tests/phpunit/api/v3/MembershipTypeTest.php

index 06f0e91b62bd0c745d4319de584f59f796367ab2..8e96e39a6ce15c02f4af7e04549329224f6b29f9 100644 (file)
@@ -757,7 +757,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       ];
       $activities[$id]['activity_type_name'] = CRM_Core_PseudoConstant::getName('CRM_Activity_BAO_Activity', 'activity_type_id', $activity['activity_type_id']);
       $activities[$id]['activity_type'] = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'activity_type_id', $activity['activity_type_id']);
-      $activities[$id]['target_contact_count'] = CRM_Utils_Array::value('target_contact_count', $activity, 0);
+      $activities[$id]['target_contact_count'] = $activity['target_contact_count'] ?? 0;
       if (!empty($activity['target_contact_count'])) {
         $displayedTarget = civicrm_api3('ActivityContact', 'get', [
           'activity_id' => $id,
@@ -1356,7 +1356,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
         $smsProviderParams['To'] = '';
       }
 
-      $doNotSms = CRM_Utils_Array::value('do_not_sms', $contact, 0);
+      $doNotSms = $contact['do_not_sms'] ?? 0;
 
       if ($doNotSms) {
         $errMsgs[] = PEAR::raiseError('Contact Does not accept SMS', NULL, PEAR_ERROR_RETURN);
@@ -2462,7 +2462,7 @@ INNER JOIN  civicrm_option_group grp ON (grp.id = option_group_id AND grp.name =
       'activity_date_time' => $params['activity_date_time'] ?? NULL,
       'check_permissions' => 1,
       'options' => [
-        'offset' => CRM_Utils_Array::value('offset', $params, 0),
+        'offset' => $params['offset'] ?? 0,
       ],
     ];
 
index 79e2ec3b8ba47c30822387cb02cb0b263afe7464..2072b2b68716aba3cca34e77bf5eb42fed6e2af8 100644 (file)
@@ -341,7 +341,7 @@ class CRM_Admin_Page_AJAX {
    * Used by jstree to incrementally load tags
    */
   public static function getTagTree() {
-    $parent = CRM_Utils_Type::escape(CRM_Utils_Array::value('parent_id', $_GET, 0), 'Integer');
+    $parent = CRM_Utils_Type::escape(($_GET['parent_id'] ?? 0), 'Integer');
     $substring = CRM_Utils_Type::escape(CRM_Utils_Array::value('str', $_GET), 'String');
     $result = [];
 
index 89010bee15455f4a3544028c22ae98a0e1061a05..d4d711296cb73d1808567d267e0b00c56a5e643c 100644 (file)
@@ -412,7 +412,7 @@ class CRM_Contact_Form_Search_Criteria {
       'street_unit' => [ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL],
     ];
 
-    $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0);
+    $parseStreetAddress = $addressOptions['street_address_parsing'] ?? 0;
     $form->assign('parseStreetAddress', $parseStreetAddress);
     foreach ($elements as $name => $v) {
       list($title, $attributes, $select, $multiSelect) = $v;
index e7cc48bd6cef485137fa62a2200fe3d4f88b6014..97ffa8453d8880fedc7e704b2df34faa01a4491d 100644 (file)
@@ -57,7 +57,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form {
     $errorFiles = ['sqlImport.errors', 'sqlImport.conflicts', 'sqlImport.duplicates', 'sqlImport.mismatch'];
 
     // check for post max size avoid when called twice
-    $snippet = CRM_Utils_Array::value('snippet', $_GET, 0);
+    $snippet = $_GET['snippet'] ?? 0;
     if (empty($snippet)) {
       CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
     }
index 3a9a441c5d0433b7053f4f4584364b2afc6a98e1..188c31ef4bcfdc0151c8eb0a2fa4900457cdacb0 100644 (file)
@@ -181,7 +181,7 @@ class CRM_Contribute_BAO_ContributionRecur extends CRM_Contribute_DAO_Contributi
       'id' => $recurID,
       'return' => ['payment_processor_id'],
     ]);
-    return (int) CRM_Utils_Array::value('payment_processor_id', $recur, 0);
+    return (int) ($recur['payment_processor_id'] ?? 0);
   }
 
   /**
index edee3b3d8a4e530f78d92411e14d2f28c2a566bb..86210384041c3ded599594b45206e6e05bfb7ac8 100644 (file)
@@ -399,7 +399,7 @@ class CRM_Core_BAO_Block {
     }
 
     // contact_id in params might be empty or the string 'null' so cast to integer
-    $contactId = (int) CRM_Utils_Array::value('contact_id', $params);
+    $contactId = (int) ($params['contact_id'] ?? 0);
     // If id is set & we haven't been passed a contact_id, retrieve it
     if (!empty($params['id']) && !isset($params['contact_id'])) {
       $entity = new $class();
index a6388e15c24a1045277fea371a1688507e09e964..7fe98ea1dd976a8bc93c1baddab03fb0e9adab1e 100644 (file)
@@ -496,7 +496,7 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard {
     foreach ($params as $dashboardIDs) {
       $contactID = CRM_Utils_Array::value('contact_id', $dashboardIDs);
       $dashboardID = CRM_Utils_Array::value('dashboard_id', $dashboardIDs);
-      $column = CRM_Utils_Array::value('column_no', $dashboardIDs, 0);
+      $column = $dashboardIDs['column_no'] ?? 0;
       $columns[$column][$dashboardID] = 0;
     }
     self::saveDashletChanges($columns, $contactID);
index e1bfa5a40ff5396df23d7d9c25912bf6e825cdde..20593b0b286eacfaf5295488df5986633393d1eb 100644 (file)
@@ -373,7 +373,6 @@ class CRM_Core_Menu {
         $values[$item['adminGroup']] = array();
         $values[$item['adminGroup']]['fields'] = array();
       }
-      $weight = CRM_Utils_Array::value('weight', $item, 0);
       $values[$item['adminGroup']]['fields']["{weight}.{$item['title']}"] = $value;
       $values[$item['adminGroup']]['component_id'] = $item['component_id'];
     }
index 894b252f7a2f619f933653e6a1971557fcc2a2a1..63ec93388ce02419e770e04a601584ec03489289 100644 (file)
@@ -29,8 +29,5 @@
  *   the generated key
  */
 function smarty_function_crmKey($params, &$smarty) {
-  return CRM_Core_Key::get(
-      $params['name'],
-      CRM_Utils_Array::value('addSequence', $params, 0)
-    );
+  return CRM_Core_Key::get($params['name'], $params['addSequence'] ?? FALSE);
 }
index 9a955b3cba99bbe4d7d357e338b2cf20b07408a8..ff9b315d553855dc46cc0125585e8a7b01a6af44 100644 (file)
@@ -421,7 +421,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
-      $eventId = (int) CRM_Utils_Array::value('event_id', $_POST);
+      $eventId = (int) ($_POST['event_id'] ?? 0);
       // Custom data of type participant role
       // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
       //       not sure if that ever really happens
index c8745fa0a5f0b745c958bbacea851f0311e43480..36fa6ea729fd8691683cc49c4119433b989afd89 100644 (file)
@@ -205,7 +205,7 @@ class CRM_Utils_Chart {
     }
 
     // rotate the x labels.
-    $chartData['xLabelAngle'] = CRM_Utils_Array::value('xLabelAngle', $rows, 0);
+    $chartData['xLabelAngle'] = $rows['xLabelAngle'] ?? 0;
     if (!empty($rows['tip'])) {
       $chartData['tip'] = $rows['tip'];
     }
index 9fd042bf3324fb56565b968f37c47a24c31a4060..d79910a4c73282781d66fb23f9973fed9aa7c80f 100644 (file)
@@ -858,7 +858,7 @@ function civicrm_api3_contact_getquick($params) {
   }
   $actualSelectElements = implode(', ', $actualSelectElements);
   $from = implode(' ', $from);
-  $limit = (int) CRM_Utils_Array::value('limit', $params);
+  $limit = (int) ($params['limit'] ?? 0);
   $limit = $limit > 0 ? $limit : Civi::settings()->get('search_autocomplete_count');
 
   // add acl clause here
index e867a9bf4824baa6e04f2a9bb876059c3c677793..fe1ceffc0b79b2f3854a5dcc1d62cba8b75a9360 100644 (file)
@@ -73,7 +73,7 @@ function _civicrm_api3_dashboard_contact_create_spec(&$params) {
 function _civicrm_api3_dashboard_contact_check_params(&$params) {
   $dashboard_id = CRM_Utils_Array::value('dashboard_id', $params);
   if ($dashboard_id) {
-    $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, CRM_Utils_Array::value('check_permissions', $params, 0));
+    $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, $params['check_permissions'] ?? FALSE);
     if (!isset($allDashlets[$dashboard_id])) {
       return civicrm_api3_create_error('Invalid or inaccessible dashboard ID');
     }
index 20a1e15d1f36d358d07073ab384b06fdc98790f6..c3dd38b069a4db2c1d9a0f957ab40d778f90ff60 100644 (file)
@@ -678,7 +678,7 @@ function civicrm_api3_job_group_rebuild($params) {
     throw new API_Exception('Could not acquire lock, another GroupRebuild process is running');
   }
 
-  $limit = CRM_Utils_Array::value('limit', $params, 0);
+  $limit = $params['limit'] ?? 0;
 
   CRM_Contact_BAO_GroupContactCache::loadAll(NULL, $limit);
   $lock->release();
index 65fe0128da644190210b43379f0efa653048b7ef..d7f6598d2f3098ce839f2c4f659283cf0d4ced8c 100644 (file)
@@ -776,25 +776,21 @@ function _civicrm_api3_apply_filters_to_dao($filterField, $filterValue, &$dao) {
 function _civicrm_api3_get_options_from_params($params, $queryObject = FALSE, $entity = '', $action = '') {
   $lowercase_entity = _civicrm_api_get_entity_name_from_camel($entity);
   $is_count = FALSE;
-  $sort = CRM_Utils_Array::value('sort', $params, 0);
-  $sort = CRM_Utils_Array::value('option.sort', $params, $sort);
-  $sort = CRM_Utils_Array::value('option_sort', $params, $sort);
 
-  $offset = CRM_Utils_Array::value('offset', $params, 0);
-  $offset = CRM_Utils_Array::value('option.offset', $params, $offset);
   // dear PHP thought it would be a good idea to transform a.b into a_b in the get/post
-  $offset = CRM_Utils_Array::value('option_offset', $params, $offset);
+  $sort = $params['option_sort'] ?? $params['option.sort'] ?? $params['sort'] ?? 0;
+  $offset = $params['option_offset'] ?? $params['option.offset'] ?? $params['offset'] ?? 0;
 
   $limit = CRM_Utils_Array::value('rowCount', $params, 25);
   $limit = CRM_Utils_Array::value('option.limit', $params, $limit);
   $limit = CRM_Utils_Array::value('option_limit', $params, $limit);
 
-  if (is_array(CRM_Utils_Array::value('options', $params))) {
+  if (isset($params['options']) && is_array($params['options'])) {
     // is count is set by generic getcount not user
-    $is_count = CRM_Utils_Array::value('is_count', $params['options']);
-    $offset = CRM_Utils_Array::value('offset', $params['options'], $offset);
-    $limit  = CRM_Utils_Array::value('limit', $params['options'], $limit);
-    $sort   = CRM_Utils_Array::value('sort', $params['options'], $sort);
+    $is_count = $params['options']['is_count'] ?? FALSE;
+    $offset = $params['options']['offset'] ?? $offset;
+    $limit = CRM_Utils_Array::value('limit', $params['options'], $limit);
+    $sort = $params['options']['sort'] ?? $sort;
   }
 
   $returnProperties = [];
@@ -869,9 +865,7 @@ function _civicrm_api3_get_options_from_params($params, $queryObject = FALSE, $e
     elseif ($n === 'id') {
       $inputParams[$lowercase_entity . '_id'] = $v;
     }
-    elseif (in_array($n, $otherVars)) {
-    }
-    else {
+    elseif (!in_array($n, $otherVars)) {
       $inputParams[$n] = $v;
       if ($v && !is_array($v) && stristr($v, 'SELECT')) {
         throw new API_Exception('invalid string');
index bd47aa24c01d69ae585a7730ce8ac26c942c7ab6..bf78045c5589d24e27c0f2f34aef4a038b9d6ca7 100644 (file)
@@ -287,7 +287,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase {
       $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($type);
       $fieldParams['option_id'] = [1 => $priceFieldValue['id']];
       $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
-      $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
+      $fieldParams['option_amount'][$rowCount] = $membetype['minimum_fee'] ?? 0;
       $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
       $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
       $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);