From 23b507ed4a4d4a47cf659ae42034c70e2a893abd Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 13 Oct 2023 19:43:38 -0400 Subject: [PATCH] CRM/Price - Refactor unnecessary uses of CRM_Utils_Array::value --- CRM/Price/BAO/LineItem.php | 4 ++-- CRM/Price/BAO/PriceField.php | 2 +- CRM/Price/BAO/PriceSet.php | 8 ++++---- CRM/Price/Form/Field.php | 14 +++++++------- CRM/Price/Form/Option.php | 6 +++--- CRM/Price/Form/Set.php | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 4d4069054a..4a1a81c85a 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -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, ]; diff --git a/CRM/Price/BAO/PriceField.php b/CRM/Price/BAO/PriceField.php index 0fb1c2e609..60b194365f 100644 --- a/CRM/Price/BAO/PriceField.php +++ b/CRM/Price/BAO/PriceField.php @@ -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]); } diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index f29b493c14..b02e04d800 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -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'])) { diff --git a/CRM/Price/Form/Field.php b/CRM/Price/Form/Field.php index 3f2b2bd6a7..5496fdabd0 100644 --- a/CRM/Price/Form/Field.php +++ b/CRM/Price/Form/Field.php @@ -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 diff --git a/CRM/Price/Form/Option.php b/CRM/Price/Form/Option.php index 94e4f0d9a8..3aeecdc00f 100644 --- a/CRM/Price/Form/Option.php +++ b/CRM/Price/Form/Option.php @@ -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; diff --git a/CRM/Price/Form/Set.php b/CRM/Price/Form/Set.php index 5abbc00ca0..c9e630058a 100644 --- a/CRM/Price/Form/Set.php +++ b/CRM/Price/Form/Set.php @@ -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; -- 2.25.1