Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] CRM/Price - Refactor unnecessary uses of CRM_Utils_Array::value #27824

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CRM/Price/BAO/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static function format($fid, $params, $fields, &$values, $amount_override
$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,
Expand All @@ -329,7 +329,7 @@ public static function format($fid, $params, $fields, &$values, $amount_override
'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,
];

Expand Down
2 changes: 1 addition & 1 deletion CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public static function priceSetValidation($priceSetId, $fields, &$error, $allowN
// 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]);
}
Expand Down
8 changes: 4 additions & 4 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public static function initSet(&$form, $entityTable = 'civicrm_event', $doNotInc
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;
}
}
Expand All @@ -610,7 +610,7 @@ public static function initSet(&$form, $entityTable = 'civicrm_event', $doNotInc
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;
}
Expand Down Expand Up @@ -879,7 +879,7 @@ public static function buildPriceSet(&$form, $component = NULL, $validFieldsOnly
'price_' . $field['id'],
$field['id'],
FALSE,
CRM_Utils_Array::value('is_required', $field, FALSE),
$field['is_required'] ?? FALSE,
NULL,
$options
);
Expand Down Expand Up @@ -1611,7 +1611,7 @@ public static function getLine(&$params, &$lineItem, $priceSetID, $field, $id):
$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'])) {
Expand Down
14 changes: 7 additions & 7 deletions CRM/Price/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,12 @@ public function submit($params) {
$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;
Expand All @@ -689,7 +689,7 @@ public function submit($params) {
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
Expand Down
6 changes: 3 additions & 3 deletions CRM/Price/Form/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public function postProcess() {
$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;
Expand Down
4 changes: 2 additions & 2 deletions CRM/Price/Form/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ public function postProcess() {
// 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;
Expand Down