dev/core#2043 Remove instance of pass-by-ref
authoreileen <emcnaughton@wikimedia.org>
Mon, 19 Oct 2020 22:46:29 +0000 (11:46 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 28 Oct 2020 20:52:55 +0000 (09:52 +1300)
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
tests/phpunit/CRM/Batch/Form/EntryTest.php

index 571d0ad2eb3b7e5bdc76a27c1c63d48c1d7697f3..fe349644421c62960f73b9858280fc9988353820 100644 (file)
@@ -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;
   }
 
   /**
index 7999141ff0700bca82488f31bd3de3c690d4d697..3d9dbbcb3f4cbd3e52d5b6f1bbdec18611b2fb9e 100644 (file)
@@ -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