Remove last pass-by-reference in completeOrder signature
authoreileen <emcnaughton@wikimedia.org>
Tue, 25 Aug 2020 20:48:12 +0000 (08:48 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 25 Aug 2020 20:48:12 +0000 (08:48 +1200)
ids is now only referred to once in the function & never altered. I have assigned that value to
a param & unset ids after that to make that clear

CRM/Contribute/BAO/Contribution.php
CRM/Core/Payment/BaseIPN.php

index a74d99bc5736d3c6d0dd9505a631a08069f71cd1..3494b5ee3d7062f73ea7ed05416261b1e64f1461 100644 (file)
@@ -4452,9 +4452,15 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
    * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
-  public static function completeOrder($input, &$ids, $objects, $isPostPaymentCreate = FALSE) {
+  public static function completeOrder($input, $ids, $objects, $isPostPaymentCreate = FALSE) {
     $transaction = new CRM_Core_Transaction();
     $contribution = $objects['contribution'];
+    // @todo see if we even need this - it's used further down to create an activity
+    // but the BAO layer should create that - we just need to add a test to cover it & can
+    // maybe remove $ids altogether.
+    $contributionContactID = $ids['related_contact'] ?? NULL;
+    // Unset ids just to make it clear it's not used again.
+    unset($ids);
     // The previous details are used when calculating line items so keep it before any code that 'does something'
     if (!empty($contribution->id)) {
       $input['prevContribution'] = CRM_Contribute_BAO_Contribution::getValues(['id' => $contribution->id]);
@@ -4565,9 +4571,9 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
     if ($input['component'] == 'contribute') {
       //CRM-4027
       $targetContactID = NULL;
-      if (!empty($ids['related_contact'])) {
+      if ($contributionContactID) {
         $targetContactID = $contribution->contact_id;
-        $contribution->contact_id = $ids['related_contact'];
+        $contribution->contact_id = $contributionContactID;
       }
       CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
     }
index 930baec01633edbfe0f1ccacc8e56d16044a25a7..e4312a5fd79781604eaac6ed56aa29a427f83935 100644 (file)
@@ -467,7 +467,7 @@ class CRM_Core_Payment_BaseIPN {
    * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
-  public function completeTransaction(&$input, &$ids, &$objects) {
+  public function completeTransaction($input, $ids, $objects) {
     CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects);
   }