From 4c3ab9d203c261d6432bbdff4460f21b0ef6ee93 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 4 Sep 2023 12:11:19 +1200 Subject: [PATCH] Remove some unnecessary variables --- CRM/Contribute/BAO/Contribution.php | 17 ++++++----------- .../phpunit/CRM/Core/Payment/BaseIPNTest.php | 19 ++++++++----------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index d3ff989685..313a3c6aa2 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2498,22 +2498,17 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac * messages * @throws \CRM_Core_Exception */ - public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText = TRUE) { + public function composeMessageArray($input, $ids, $values = [], $returnMessageText = TRUE) { $ids = array_merge(self::getComponentDetails($this->id), $ids); if (empty($ids['contact']) && isset($this->contact_id)) { $ids['contact'] = $this->contact_id; } - - if (empty($this->_component)) { - if (!empty($ids['event'])) { - $this->_component = 'event'; - } - else { - $this->_component = $input['component'] ?? 'contribute'; - } + if (!empty($ids['event'])) { + $this->_component = 'event'; + } + else { + $this->_component = 'contribute'; } - // @todo remove strtolower - check consistency - $this->_component = strtolower($this->_component); // If the object is not fully populated then make sure it is - this is a more about legacy paths & cautious // refactoring than anything else, and has unit test coverage. diff --git a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php index 7abbfe351f..d15c0f7d7f 100644 --- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php @@ -122,8 +122,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->_setUpMembershipObjects(); $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; - $values = []; - $msg = $contribution->composeMessageArray($this->input, $this->ids, $values); + $msg = $contribution->composeMessageArray($this->input, $this->ids); $this->assertIsArray($msg, 'Message returned as an array in line'); $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); $this->assertStringContainsString('Membership Type: General', $msg['body']); @@ -139,9 +138,8 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { public function testSendMailMembershipObjectsNoLeakage(): void { $this->_setUpMembershipObjects(); $contribution = new CRM_Contribute_BAO_Contribution(); - $values = []; $contribution->id = $this->_contributionId; - $msg = $contribution->composeMessageArray($this->input, $this->ids, $values); + $msg = $contribution->composeMessageArray($this->input, $this->ids); $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); $this->assertStringContainsString('Membership Type: General', $msg['body']); @@ -154,7 +152,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->input['invoiceID'] = 'abc'; $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; - $msg = $contribution->composeMessageArray($this->input, $this->ids, $values); + $msg = $contribution->composeMessageArray($this->input, $this->ids); $this->assertEquals('Dr. Donald Duck II', $msg['to']); $this->assertStringContainsString('Membership Type: Fowl', $msg['body']); } @@ -168,7 +166,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->_setUpMembershipObjects(); $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; - $msg = $contribution->composeMessageArray($this->input, $this->ids, $values); + $msg = $contribution->composeMessageArray($this->input, $this->ids); $this->assertIsArray($msg, 'Message not returned as an array'); $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); $this->assertStringContainsString('Membership Type: General', $msg['body']); @@ -185,7 +183,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; $contribution->loadRelatedObjects($this->_processorId, $this->ids); - $msg = $contribution->composeMessageArray($this->input, $this->ids, $values); + $msg = $contribution->composeMessageArray($this->input, $this->ids); $this->assertStringContainsString('registration has been received and your status has been updated to Attended.', $msg['body']); $this->assertStringContainsString('Annual CiviCRM meet', $msg['html']); } @@ -197,7 +195,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->_setUpParticipantObjects(); $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; - $msg = $contribution->composeMessageArray($this->input, $this->ids, $values); + $msg = $contribution->composeMessageArray($this->input, $this->ids); $this->assertEquals('Mr. Anthony Anderson II', $msg['to']); $this->assertStringContainsString('Thank you for your registration', $msg['body']); } @@ -230,7 +228,6 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $event->id = $this->_eventId; $event->is_email_confirm = FALSE; $event->save(); - $values = []; $tablesToTruncate = [ 'civicrm_mailing_spool', ]; @@ -238,7 +235,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $mut = new CiviMailUtils($this, TRUE); $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; - $contribution->composeMessageArray($this->input, $this->ids, $values); + $contribution->composeMessageArray($this->input, $this->ids); $mut->assertMailLogEmpty('no mail should have been send as event set to no confirm'); $mut->stop(); } @@ -252,7 +249,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->_setUpPledgeObjects(); $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $this->_contributionId; - $msg = $contribution->composeMessageArray($this->input, $this->ids, $values); + $msg = $contribution->composeMessageArray($this->input, $this->ids); $this->assertStringContainsString('Contribution Information', $msg['html']); } -- 2.25.1