Remove instances of variable variables
authoreileen <emcnaughton@wikimedia.org>
Mon, 19 Oct 2020 01:42:09 +0000 (14:42 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 19 Oct 2020 04:48:17 +0000 (17:48 +1300)
Minor code readability tidy up covered by EntryTest:testProcessMembership

CRM/Batch/Form/Entry.php
CRM/Core/BAO/UFGroup.php
tests/phpunit/CRM/Batch/Form/EntryTest.php

index 35c407a79f267102716643a7d1e62d989d065c35..aefa3a2b156443251a696eafdb053bcb8ce960f1 100644 (file)
@@ -849,45 +849,16 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
           CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams);
         }
         else {
-          $dateTypes = [
-            'membership_join_date' => 'joinDate',
-            'membership_start_date' => 'startDate',
-            'membership_end_date' => 'endDate',
-          ];
-
-          $dates = [
-            'join_date',
-            'start_date',
-            'end_date',
-            'reminder_date',
-          ];
-          foreach ($dateTypes as $dateField => $dateVariable) {
-            $$dateVariable = CRM_Utils_Date::processDate($value[$dateField]);
-            $fDate[$dateField] = $value[$dateField] ?? NULL;
-          }
-
-          $calcDates = [];
-          $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId,
-            $joinDate, $startDate, $endDate
+          $calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId,
+            $value['membership_join_date'] ?? NULL, $value['membership_start_date'] ?? NULL, $value['membership_end_date'] ?? NULL
           );
-
-          foreach ($calcDates as $memType => $calcDate) {
-            foreach ($dates as $d) {
-              //first give priority to form values then calDates.
-              $date = $value[$d] ?? NULL;
-              if (!$date) {
-                $date = $calcDate[$d] ?? NULL;
-              }
-
-              $value[$d] = CRM_Utils_Date::processDate($date);
-            }
-          }
+          $value['join_date'] = $value['membership_join_date'] ?? $calcDates['join_date'];
+          $value['start_date'] = $value['membership_start_date'] ?? $calcDates['start_date'];
+          $value['end_date'] = $value['membership_end_date'] ?? $calcDates['end_date'];
 
           unset($value['membership_start_date']);
           unset($value['membership_end_date']);
-          $ids = [];
-          // @todo stop passing empty $ids
-          $membership = CRM_Member_BAO_Membership::create($value, $ids);
+          $membership = CRM_Member_BAO_Membership::create($value);
         }
 
         //process premiums
index 412f753ce7cf424d20effc9e7cdbc0401b795169..0b5df8b7a649912905082f0e63d031aee8b30b84 100644 (file)
@@ -246,7 +246,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * and format for use with buildProfile. This is the SQL analog of
    * formatUFFields().
    *
-   * @param mix $id
+   * @param int $id
    *   The id of the UF group or ids of ufgroup.
    * @param bool|int $register are we interested in registration fields
    * @param int $action
index 6b730b171bc1d613aecf8018cf57ebe0d0e8530e..21ff503d6b33c48331e9fdbbb4942c7e570cb246 100644 (file)
@@ -171,12 +171,12 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
     $this->setCurrencySeparators($thousandSeparator);
 
     $form = new CRM_Batch_Form_Entry();
-    $profileID = $this->callAPISuccessGetValue('UFGroup', ['return' => 'id', 'name' => 'membership_batch_entry']);
+    $profileID = (int) $this->callAPISuccessGetValue('UFGroup', ['return' => 'id', 'name' => 'membership_batch_entry']);
     $form->_fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::VIEW);
 
     $params = $this->getMembershipData();
     $this->assertTrue($form->testProcessMembership($params));
-    $result = $this->callAPISuccess('membership', 'get', []);
+    $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
     $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
@@ -190,7 +190,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
     //check start dates #1 should default to 1 Jan this year, #2 should be as entered
     $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
     $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
-    $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
+    $this->assertEquals(date('Y-m-d'), $result['values'][3]['join_date']);
     $result = $this->callAPISuccess('contribution', 'get', ['return' => ['total_amount', 'trxn_id']]);
     $this->assertEquals(3, $result['count']);
     foreach ($result['values'] as $key => $contribution) {