From 818f20f02727cbf11b1b9da5adfee4da78fe6f2f Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 20 Oct 2020 11:46:29 +1300 Subject: [PATCH] dev/core#2043 Remove instance of pass-by-ref The postProcess function onlly uses one value generated in the private function processMembersip. This makes that a return value rather than something hidden in the pass-by-ref --- CRM/Batch/Form/Entry.php | 19 +++++++++++-------- tests/phpunit/CRM/Batch/Form/EntryTest.php | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 571d0ad2eb..fe34964442 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -433,7 +433,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $this->processContribution($params); } elseif ($this->_batchInfo['type_id'] == $batchTypes['Membership']) { - $this->processMembership($params); + $params['actualBatchTotal'] = $this->processMembership($params); } // update batch to close status @@ -623,7 +623,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { //process premiums if (!empty($value['product_name'])) { if ($value['product_name'][0] > 0) { - list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); + [$products, $options] = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $value['hidden_Premium'] = 1; $value['product_option'] = CRM_Utils_Array::value( @@ -663,13 +663,16 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { * Process membership records. * * @param array $params - * Associated array of submitted values. + * Array of submitted values. * + * @return float + * batch total monetary amount. * - * @return bool + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ - private function processMembership(&$params) { - + private function processMembership(array $params) { + $batchTotal = 0; // get the price set associated with offline membership $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name'); $this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); @@ -755,7 +758,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $value['total_amount'] = (float) $value['total_amount']; } - $params['actualBatchTotal'] += $value['total_amount']; + $batchTotal += $value['total_amount']; unset($value['financial_type']); unset($value['payment_instrument']); @@ -890,7 +893,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } } } - return TRUE; + return $batchTotal; } /** diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php index 7999141ff0..3d9dbbcb3f 100644 --- a/tests/phpunit/CRM/Batch/Form/EntryTest.php +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -177,7 +177,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { $form->_fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::VIEW); $params = $this->getMembershipData(); - $this->assertTrue($form->testProcessMembership($params)); + $this->assertEquals(4500.0, $form->testProcessMembership($params)); $result = $this->callAPISuccess('membership', 'get'); $this->assertEquals(3, $result['count']); //check start dates #1 should default to 1 Jan this year, #2 should be as entered @@ -268,7 +268,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { $params['field'][2]['membership_end_date'] = "2017-03-31"; $params['field'][2]['receive_date'] = "2016-04-01"; - $this->assertTrue($form->testProcessMembership($params)); + $this->assertEquals(3.0, $form->testProcessMembership($params)); $result = $this->callAPISuccess('membership', 'get')['values']; // renewal dates should be from current if start_date and end_date is passed as NULL -- 2.25.1