From b8bb9d0601e2cb141c534fd5be99ae393fae8f99 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 19 Oct 2020 14:42:09 +1300 Subject: [PATCH] Remove instances of variable variables Minor code readability tidy up covered by EntryTest:testProcessMembership --- CRM/Batch/Form/Entry.php | 41 ++++------------------ CRM/Core/BAO/UFGroup.php | 2 +- tests/phpunit/CRM/Batch/Form/EntryTest.php | 6 ++-- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 35c407a79f..aefa3a2b15 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -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 diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 412f753ce7..0b5df8b7a6 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -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 diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php index 6b730b171b..21ff503d6b 100644 --- a/tests/phpunit/CRM/Batch/Form/EntryTest.php +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -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) { -- 2.25.1