Switch to non-static functions
authoreileen <emcnaughton@wikimedia.org>
Thu, 10 Dec 2020 20:48:35 +0000 (09:48 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 10 Dec 2020 20:48:35 +0000 (09:48 +1300)
I realise these functions are static so that the formRule can call them - but
the formRule has access to the form object and the intention was obviously always
that the formRule can call functions on the form. This cleans that up:

CRM/Member/Form.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php

index 3ae6973ef52b097a5b3cc654d910b77f6a3a75f0..c2c4dfa871eb41f38b0fd9ee9b52762c7f41b8f1 100644 (file)
@@ -416,7 +416,7 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
    *
    * @return array
    */
-  protected static function getPriceSetDetails($params) {
+  protected function getPriceSetDetails(array $params): ?array {
     $priceSetID = $params['price_set_id'] ?? NULL;
     if ($priceSetID) {
       return CRM_Price_BAO_PriceSet::getSetDetail($priceSetID);
@@ -436,10 +436,10 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
    *
    * @return int
    */
-  protected static function getPriceSetID($params) {
+  protected function getPriceSetID(array $params): int {
     $priceSetID = $params['price_set_id'] ?? NULL;
     if (!$priceSetID) {
-      $priceSetDetails = self::getPriceSetDetails($params);
+      $priceSetDetails = $this->getPriceSetDetails($params);
       return (int) key($priceSetDetails);
     }
     return (int) $priceSetID;
@@ -452,9 +452,9 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
    *
    * @return array
    */
-  protected function setPriceSetParameters($formValues) {
-    $this->_priceSetId = self::getPriceSetID($formValues);
-    $priceSetDetails = self::getPriceSetDetails($formValues);
+  protected function setPriceSetParameters(array $formValues): array {
+    $this->_priceSetId = $this->getPriceSetID($formValues);
+    $priceSetDetails = $this->getPriceSetDetails($formValues);
     $this->_priceSet = $priceSetDetails[$this->_priceSetId];
     // process price set and get total amount and line items.
     $this->ensurePriceParamsAreSet($formValues);
index b5846d2177785a5ba0c03fa2b1887e09d5c1a670..642079722ab49a300a11d2db6f7b9fe8a3f71e9e 100644 (file)
@@ -651,8 +651,8 @@ DESC limit 1");
   public static function formRule($params, $files, $self) {
     $errors = [];
 
-    $priceSetId = self::getPriceSetID($params);
-    $priceSetDetails = self::getPriceSetDetails($params);
+    $priceSetId = $self->getPriceSetID($params);
+    $priceSetDetails = $self->getPriceSetDetails($params);
 
     $selectedMemberships = self::getSelectedMemberships($priceSetDetails[$priceSetId], $params);
 
index dcf50ec085d829acbb964483e9e300104696de9b..6abca4299df214fa22c4257cf84bfc758dabc224 100644 (file)
@@ -782,7 +782,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
   protected function getOrderParams(): array {
     $order = new CRM_Financial_BAO_Order();
     $order->setPriceSelectionFromUnfilteredInput($this->_params);
-    $order->setPriceSetID(self::getPriceSetID($this->_params));
+    $order->setPriceSetID($this->getPriceSetID($this->_params));
     $order->setOverrideTotalAmount($this->_params['total_amount']);
     $order->setOverrideFinancialTypeID((int) $this->_params['financial_type_id']);
     return [