Remove some unnecessary variables
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 4 Sep 2023 00:11:19 +0000 (12:11 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 4 Sep 2023 00:11:19 +0000 (12:11 +1200)
CRM/Contribute/BAO/Contribution.php
tests/phpunit/CRM/Core/Payment/BaseIPNTest.php

index d3ff989685a7e602156e5840b16db341df50bf56..313a3c6aa2b4a64bd1db37d2789215c24bd4331b 100644 (file)
@@ -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.
index 7abbfe351fcbb729174c92d7d459a81e91f69024..d15c0f7d7febe8f8edad6cad517968f76eca4e68 100644 (file)
@@ -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']);
   }