From bc54561fc8f1b5a4e920bc08b026a86079d73704 Mon Sep 17 00:00:00 2001 From: colemanw <coleman@civicrm.org> Date: Tue, 6 Feb 2024 12:09:38 -0500 Subject: [PATCH] Cleanup - Replace more nested CRM_Utils_Array::value with ?? --- CRM/Contact/BAO/Query.php | 2 +- CRM/Contact/BAO/Relationship.php | 2 +- CRM/Contribute/BAO/Contribution.php | 5 +---- CRM/Contribute/Form/Contribution.php | 4 ++-- CRM/Contribute/Form/Contribution/Confirm.php | 4 ++-- CRM/Member/Form/Membership.php | 2 +- CRM/Price/BAO/LineItem.php | 2 +- CRM/Report/Form.php | 2 +- CRM/Report/Utils/Report.php | 2 +- 9 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 9249c65c5bc..139b41619c2 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -6889,7 +6889,7 @@ AND displayRelType.is_active = 1 if (!empty($field) && empty($field['name'])) { // standardising field formatting here - over time we can phase out variants. // all paths using this currently unit tested - $field['name'] = CRM_Utils_Array::value('field_name', $field, CRM_Utils_Array::value('idCol', $field, $fieldName)); + $field['name'] = $field['field_name'] ?? $field['idCol'] ?? $fieldName; } return $field; } diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index fa111ba3655..c87a090f4a7 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -158,7 +158,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship implemen * @throws \CRM_Core_Exception */ public static function add($params, $ids = []) { - $params['id'] = CRM_Utils_Array::value('relationship', $ids, CRM_Utils_Array::value('id', $params)); + $params['id'] = $ids['relationship'] ?? $params['id'] ?? NULL; $hook = 'create'; if ($params['id']) { diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 5db97fb7c3d..affa7ced5c6 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1833,10 +1833,7 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ } } - $paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $input, CRM_Utils_Array::value( - 'paymentProcessor', - $ids - )); + $paymentProcessorID = $input['payment_processor_id'] ?? $ids['paymentProcessor'] ?? NULL; if (!isset($input['payment_processor_id']) && !$paymentProcessorID && $contribution->contribution_page_id) { $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 09d4cabe721..d8b15bd113f 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1239,7 +1239,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP 'is_test' => $isTest, 'campaign_id' => $this->_params['campaign_id'] ?? NULL, 'contribution_page_id' => $this->_params['contribution_page_id'] ?? NULL, - 'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)), + 'source' => $paymentParams['source'] ?? $paymentParams['description'] ?? NULL, 'thankyou_date' => $this->_params['thankyou_date'] ?? NULL, ]; $contributionParams['payment_instrument_id'] = $this->_paymentProcessor['payment_instrument_id']; @@ -2016,7 +2016,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } $params['line_item'] = $lineItem; $params['payment_processor_id'] = $params['payment_processor'] = $this->_paymentProcessor['id'] ?? NULL; - $params['tax_amount'] = CRM_Utils_Array::value('tax_amount', $submittedValues, CRM_Utils_Array::value('tax_amount', $this->_values)); + $params['tax_amount'] = $submittedValues['tax_amount'] ?? $this->_values['tax_amount'] ?? NULL; //create contribution. if ($isQuickConfig) { $params['is_quick_config'] = 1; diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 3a539855495..4b9103b8e7c 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -2514,13 +2514,13 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr 'id' => $paymentParams['contribution_id'] ?? NULL, 'contact_id' => $contactID, 'is_test' => $isTest, - 'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)), + 'source' => $paymentParams['source'] ?? $paymentParams['description'] ?? NULL, ]; // CRM-21200: Don't overwrite contribution details during 'Pay now' payment if (empty($form->_params['contribution_id'])) { $contributionParams['contribution_page_id'] = $form->_id; - $contributionParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $paymentParams, CRM_Utils_Array::value('campaign_id', $form->_values)); + $contributionParams['campaign_id'] = $paymentParams['campaign_id'] ?? $form->_values['campaign_id'] ?? NULL; } // In case of 'Pay now' payment, append the contribution source with new text 'Paid later via page ID: N.' else { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 42262451c72..f36f7ebb978 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1063,7 +1063,7 @@ DESC limit 1"); 'line_items' => $this->getLineItemForOrderApi(), 'is_test' => $this->isTest(), 'campaign_id' => $this->getSubmittedValue('campaign_id'), - 'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)), + 'source' => $paymentParams['source'] ?? $paymentParams['description'] ?? NULL, 'payment_instrument_id' => $this->getPaymentInstrumentID(), 'financial_type_id' => $this->getFinancialTypeID(), 'receive_date' => $this->getReceiveDate(), diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index f54b31133ae..eb48202e851 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -677,7 +677,7 @@ WHERE li.contribution_id = %1"; $updatedAmount = CRM_Price_BAO_LineItem::getLineTotal($contributionId); } else { - $updatedAmount = CRM_Utils_Array::value('amount', $params, CRM_Utils_Array::value('total_amount', $params)); + $updatedAmount = $params['amount'] ?? $params['total_amount'] ?? NULL; } if (strlen($params['tax_amount']) != 0) { $taxAmount = $params['tax_amount']; diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 7e523d79cea..dbb474afe75 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -820,7 +820,7 @@ class CRM_Report_Form extends CRM_Core_Form { $expFields = []; // higher preference to bao object - $daoOrBaoName = CRM_Utils_Array::value('bao', $table, CRM_Utils_Array::value('dao', $table)); + $daoOrBaoName = $table['bao'] ?? $table['dao'] ?? NULL; if ($daoOrBaoName) { if (method_exists($daoOrBaoName, 'exportableFields')) { diff --git a/CRM/Report/Utils/Report.php b/CRM/Report/Utils/Report.php index 33e5f734290..dc95ffd95b2 100644 --- a/CRM/Report/Utils/Report.php +++ b/CRM/Report/Utils/Report.php @@ -390,7 +390,7 @@ WHERE inst.report_id = %1"; $_REQUEST['sendmail'] = CRM_Utils_Array::value('sendmail', $params, 1); // if cron is run from terminal --output is reserved, and therefore we would provide another name 'format' - $_REQUEST['output'] = CRM_Utils_Array::value('format', $params, CRM_Utils_Array::value('output', $params, 'pdf')); + $_REQUEST['output'] = $params['format'] ?? $params['output'] ?? 'pdf'; $_REQUEST['reset'] = CRM_Utils_Array::value('reset', $params, 1); $optionVal = self::getValueFromUrl($instanceId); -- GitLab