From cd3457751ed52420ecc62e5aaf64146952062e6c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 8 Aug 2021 18:02:35 +1200 Subject: [PATCH] [Ref] Clarify what parameters are passed in this function is called from 2 places with 4 keys in the array always set & no others --- CRM/Contribute/BAO/Contribution.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index f4f5f4fbea75..bb3dfe486a67 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2079,26 +2079,22 @@ public static function checkOnlinePendingContribution($componentId, $componentNa * */ public static function transitionComponents($params) { + $contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['contribution_status_id']); + $previousStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $params['previous_contribution_status_id']); // @todo fix the one place that calls this function to use Payment.create // remove this. // get minimum required values. - $contactId = $params['contact_id'] ?? NULL; - $componentId = $params['component_id'] ?? NULL; - $componentName = $params['componentName'] ?? NULL; - $contributionId = $params['contribution_id'] ?? NULL; - $contributionStatusId = $params['contribution_status_id'] ?? NULL; + $contactId = NULL; + $componentId = NULL; + $componentName = NULL; + $contributionId = $params['contribution_id']; + $contributionStatusId = $params['contribution_status_id']; // if we already processed contribution object pass previous status id. - $previousContriStatusId = $params['previous_contribution_status_id'] ?? NULL; - - $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); + $previousContriStatusId = $params['previous_contribution_status_id']; // we process only ( Completed, Cancelled, or Failed ) contributions. - if (!$contributionId || - !in_array($contributionStatusId, [ - array_search('Completed', $contributionStatuses), - ]) - ) { + if (!$contributionId || $contributionStatus !== 'Completed') { return; } @@ -2170,11 +2166,11 @@ public static function transitionComponents($params) { 'status_id' ); } - if ($contributionStatusId == array_search('Completed', $contributionStatuses)) { + if ($contributionStatus === 'Completed') { // only pending contribution related object processed. if ($previousContriStatusId && - !in_array($contributionStatuses[$previousContriStatusId], [ + !in_array($previousStatus, [ 'Pending', 'Partially paid', ]) @@ -2183,7 +2179,7 @@ public static function transitionComponents($params) { return; } elseif (!$previousContriStatusId && - !in_array($contributionStatuses[$contribution->contribution_status_id], [ + !in_array($contributionStatus, [ 'Pending', 'Partially paid', ])