CRM/Price - Refactor unnecessary uses of CRM_Utils_Array::value
authorcolemanw <coleman@civicrm.org>
Fri, 13 Oct 2023 23:43:38 +0000 (19:43 -0400)
committercolemanw <coleman@civicrm.org>
Sat, 14 Oct 2023 03:23:19 +0000 (23:23 -0400)
CRM/Price/BAO/LineItem.php
CRM/Price/BAO/PriceField.php
CRM/Price/BAO/PriceSet.php
CRM/Price/Form/Field.php
CRM/Price/Form/Option.php
CRM/Price/Form/Set.php

index 4d4069054a5e7cf66bd3392a76cc5c33a8ca7e87..4a1a81c85abece7e84b98d4547dea455cfd51444 100644 (file)
@@ -311,7 +311,7 @@ WHERE li.contribution_id = %1";
       $qty = (float) $qty;
       $price = (float) ($amount_override === NULL ? $options[$oid]['amount'] : $amount_override);
 
-      $participantsPerField = (int) CRM_Utils_Array::value('count', $options[$oid], 0);
+      $participantsPerField = (int) ($options[$oid]['count'] ?? 0);
 
       $values[$oid] = [
         'price_field_id' => $fid,
@@ -329,7 +329,7 @@ WHERE li.contribution_id = %1";
         'auto_renew' => $options[$oid]['auto_renew'] ?? NULL,
         'html_type' => $fields['html_type'],
         'financial_type_id' => $options[$oid]['financial_type_id'] ?? NULL,
-        'tax_amount' => CRM_Utils_Array::value('tax_amount', $options[$oid], 0),
+        'tax_amount' => $options[$oid]['tax_amount'] ?? 0,
         'non_deductible_amount' => $options[$oid]['non_deductible_amount'] ?? NULL,
       ];
 
index 0fb1c2e609072b24205a93814868ef05b7ea1b3a..60b194365f6a1fbae2406bad776b9666c253495b 100644 (file)
@@ -741,7 +741,7 @@ WHERE  id IN (" . implode(',', array_keys($priceFields)) . ')';
       // now we have all selected amount in hand.
       $totalAmount = array_sum($selectedAmounts);
       // The form offers a field to enter the amount paid. This may differ from the amount that is due to complete the purchase
-      $totalPaymentAmountEnteredOnForm = CRM_Utils_Array::value('total_amount', $fields);
+      $totalPaymentAmountEnteredOnForm = $fields['total_amount'] ?? NULL;
       if ($totalAmount < 0) {
         $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', [1 => $componentName]);
       }
index f29b493c14734781feb4cfc7c3e987b561436dbb..b02e04d8009bd53790233b40736408d0e8dfd028 100644 (file)
@@ -595,7 +595,7 @@ WHERE  id = %1";
           if (!empty($form->_priceSet['fields'])) {
             foreach ($form->_priceSet['fields'] as $field) {
               foreach ($field['options'] as $option) {
-                $count = CRM_Utils_Array::value('count', $option, 0);
+                $count = $option['count'] ?? 0;
                 $optionsCountDetails['fields'][$field['id']]['options'][$option['id']] = $count;
               }
             }
@@ -610,7 +610,7 @@ WHERE  id = %1";
         if (!empty($form->_priceSet['fields'])) {
           foreach ($form->_priceSet['fields'] as $field) {
             foreach ($field['options'] as $option) {
-              $maxVal = CRM_Utils_Array::value('max_value', $option, 0);
+              $maxVal = $option['max_value'] ?? 0;
               $optionsMaxValueDetails['fields'][$field['id']]['options'][$option['id']] = $maxVal;
               $optionsMaxValueTotal += $maxVal;
             }
@@ -879,7 +879,7 @@ WHERE  id = %1";
             'price_' . $field['id'],
             $field['id'],
             FALSE,
-            CRM_Utils_Array::value('is_required', $field, FALSE),
+            $field['is_required'] ?? FALSE,
             NULL,
             $options
           );
@@ -1611,7 +1611,7 @@ WHERE     ct.id = cp.financial_type_id AND
         $amount_override = NULL;
 
         if ($priceSetID && count(self::filterPriceFieldsFromParams($priceSetID, $params)) === 1) {
-          $amount_override = CRM_Utils_Array::value('total_amount', $params);
+          $amount_override = $params['total_amount'] ?? NULL;
         }
         CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem, $amount_override);
         if (!empty($field['options'][$optionValueId]['tax_rate'])) {
index 3f2b2bd6a7474ffc4fc94d5846b9c7435e986faf..5496fdabd089e17281e8b2a09b38590a61dbcafb 100644 (file)
@@ -666,12 +666,12 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
       $params['option_amount'][$key] = CRM_Utils_Rule::cleanMoney($amount);
     }
 
-    $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE);
-    $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
-    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
-    $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE);
-    $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
-    $params['count'] = CRM_Utils_Array::value('count', $params, FALSE);
+    $params['is_display_amounts'] = $params['is_display_amounts'] ?? FALSE;
+    $params['is_required'] = $params['is_required'] ?? FALSE;
+    $params['is_active'] = $params['is_active'] ?? FALSE;
+    $params['financial_type_id'] = $params['financial_type_id'] ?? FALSE;
+    $params['visibility_id'] = $params['visibility_id'] ?? FALSE;
+    $params['count'] = $params['count'] ?? FALSE;
 
     // need the FKEY - price set id
     $params['price_set_id'] = $this->_sid;
@@ -689,7 +689,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form {
     if (isset($params['option_name'])) {
       $params['option_value'] = $params['option_name'];
     }
-    $params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, FALSE);
+    $params['is_enter_qty'] = $params['is_enter_qty'] ?? FALSE;
 
     if ($params['html_type'] === 'Text') {
       // if html type is Text, force is_enter_qty on
index 94e4f0d9a8f5fb8d3a8d776109056960a0177148..3aeecdc00f4c267937560c787b254c7b1ffb3f60 100644 (file)
@@ -328,9 +328,9 @@ class CRM_Price_Form_Option extends CRM_Core_Form {
         $params[$field] = CRM_Utils_Rule::cleanMoney(trim($params[$field]));
       }
       $params['price_field_id'] = $this->_fid;
-      $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
-      $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
-      $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
+      $params['is_default'] = $params['is_default'] ?? FALSE;
+      $params['is_active'] = $params['is_active'] ?? FALSE;
+      $params['visibility_id'] = $params['visibility_id'] ?? FALSE;
       $ids = [];
       if ($this->_oid) {
         $params['id'] = $this->_oid;
index 5abbc00ca0277938e6842c32043bc194c0a97b95..c9e630058ac469cd0231282dcc8c5fb5ae875b72 100644 (file)
@@ -243,8 +243,8 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
     // get the submitted form values.
     $params = $this->controller->exportValues('Set');
     $nameLength = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'name');
-    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
-    $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE);
+    $params['is_active'] = $params['is_active'] ?? FALSE;
+    $params['financial_type_id'] = $params['financial_type_id'] ?? FALSE;
 
     $compIds = [];
     $extends = $params['extends'] ?? NULL;