Awight has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/190484

Change subject: WIP rename getData_Unstaged_Escaped
......................................................................

WIP rename getData_Unstaged_Escaped

I think "normalized" better reflects intention and usage.

Change-Id: I7f541dff43cb168466b3fe4a98524615cb93f0b2
---
M gateway_common/gateway.adapter.php
1 file changed, 40 insertions(+), 35 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/84/190484/1

diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index 2850045..445fac1 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -570,30 +570,35 @@
        }
 
        /**
-        * This is the ONLY getData type function anything should be using
-        * outside the adapter.
+        * Get the normalized value for a key
+        *
+        * This is the main access point for external code, which should never 
need
+        * to access staged data.
+        *
         * Short explanation of the data population up to now:
         *      *) When the gateway adapter is constructed, it constructs a 
DonationData
         *              object.
         *      *) On construction, the DonationData object pulls donation data 
from an
         *              appropriate source, and normalizes the entire data set 
for storage.
-        *      *) The gateway adapter pulls normalized, html escaped data out 
of the
-        *              DonationData object, as the base of its own data set.
+        *      *) The gateway adapter pulls normalized data out of the 
DonationData
+        *          object, as the base of its own data set.
         * @param string $val The specific key you're looking for (if any)
-        * @return mixed An array of all the raw, unstaged (but normalized and
-        * sanitized) data sent to the adapter, or if $val was set, either the
-        * specific value held for $val, or null if none exists.
+        * @return mixed|null The raw, unstaged (but normalized and 
semi-sanitized)
+        *     data, for $key, or null if none exists.
         */
-       public function getData_Unstaged_Escaped( $val = '' ) {
-               if ( $val === '' ) {
-                       return $this->unstaged_data;
+       public function getNormalized( $key ) {
+               if ( array_key_exists( $key, $this->unstaged_data ) ) {
+                       return $this->unstaged_data[$key];
                } else {
-                       if ( array_key_exists( $val, $this->unstaged_data ) ) {
-                               return $this->unstaged_data[$val];
-                       } else {
-                               return null;
-                       }
+                       return null;
                }
+       }
+
+       /**
+        * Get it all
+        */
+       public function getAllNormalized() {
+               return $this->unstaged_data;
        }
 
        /**
@@ -1091,7 +1096,7 @@
 
                                //in the event that we have a redirect 
transaction that never displays the form,
                                //save this most recent one before we leave.
-                               $this->session_pushRapidHTMLForm( 
$this->getData_Unstaged_Escaped( 'ffname' ) );
+                               $this->session_pushRapidHTMLForm( 
$this->getNormalized( 'ffname' ) );
 
                                $this->setTransactionResult( array(
                                        'status' => TRUE,
@@ -1304,7 +1309,7 @@
         */
        public function getPaymentMethod() {
                //FIXME: this should return the final calculated method
-               return $this->getData_Unstaged_Escaped('payment_method');
+               return $this->getNormalized('payment_method');
        }
 
        /**
@@ -1325,7 +1330,7 @@
         */
        public function getPaymentSubmethod() {
 
-               return $this->getData_Unstaged_Escaped('payment_submethod');
+               return $this->getNormalized('payment_submethod');
        }
 
        /**
@@ -1360,7 +1365,7 @@
                $retval = false;    // By default return that we failed
 
                $gatewayName = self::getGatewayName();
-               $email = $this->getData_Unstaged_Escaped( 'email' );
+               $email = $this->getNormalized( 'email' );
 
                /**
                 * This log line is pretty important. Usually when a donor 
contacts us
@@ -1689,7 +1694,7 @@
                }
 
                $params = array(
-                       'contribution_id' => $this->getData_Unstaged_Escaped( 
'contribution_tracking_id' ),
+                       'contribution_id' => $this->getNormalized( 
'contribution_tracking_id' ),
                        'duration' => $this->getStopwatch( $function ),
                        'gateway' => self::getGatewayName(),
                        'function' => $function,
@@ -1899,11 +1904,11 @@
        protected function getStompTransaction( $antiMessage = false, 
$recoverTimestamp = false ) {
                $transaction = array(
                        'gateway_txn_id' => $this->getTransactionGatewayTxnID(),
-                       'payment_method' => $this->getData_Unstaged_Escaped( 
'payment_method' ),
+                       'payment_method' => $this->getNormalized( 
'payment_method' ),
                        'response' => $this->getTransactionMessage(),
                        'correlation-id' => $this->getCorrelationID(),
                        'php-message-class' => 
'SmashPig\CrmLink\Messages\DonationInterfaceMessage',
-                       'gateway' => $this->getData_Unstaged_Escaped( 'gateway' 
),
+                       'gateway' => $this->getNormalized( 'gateway' ),
                );
 
                if ( $antiMessage == true ) {
@@ -1912,7 +1917,7 @@
                } else {
                        // Else we actually need the rest of the data
                        $stomp_data = array_intersect_key(
-                               $this->getData_Unstaged_Escaped(),
+                               $this->getAllNormalized(),
                                array_flip( 
$this->dataObj->getStompMessageFields() )
                        );
 
@@ -1924,11 +1929,11 @@
                        // if we're attempting to recover some data: ie: we're 
an orphan
                        $timestamp = null;
                        if ( $recoverTimestamp === true ) {
-                               if ( !is_null( $this->getData_Unstaged_Escaped( 
'date' ) ) ) {
-                                       $timestamp = 
$this->getData_Unstaged_Escaped( 'date' );
-                               } elseif ( !is_null( 
$this->getData_Unstaged_Escaped( 'ts' ) ) ) {
+                               if ( !is_null( $this->getNormalized( 'date' ) ) 
) {
+                                       $timestamp = $this->getNormalized( 
'date' );
+                               } elseif ( !is_null( $this->getNormalized( 'ts' 
) ) ) {
                                        // That this works is mildly surprising
-                                       $timestamp = strtotime( 
$this->getData_Unstaged_Escaped( 'ts' ) );
+                                       $timestamp = strtotime( 
$this->getNormalized( 'ts' ) );
                                }
                        }
                        $transaction['date'] = ( $timestamp === null ) ? time() 
: $timestamp;
@@ -1963,14 +1968,14 @@
                        'payment_method', //the stomp sender gets mad if we 
don't have this. @TODO: Stop being lazy someday.
                );
                foreach ( $these_too as $field ) {
-                       $transaction[$field] = $this->getData_Unstaged_Escaped( 
$field );
+                       $transaction[$field] = $this->getNormalized( $field );
                }
 
                return $transaction;
        }
 
        protected function getCorrelationID(){
-               return $this->getIdentifier() . '-' . 
$this->getData_Unstaged_Escaped('order_id');
+               return $this->getIdentifier() . '-' . 
$this->getNormalized('order_id');
        }
 
        /**
@@ -2067,16 +2072,16 @@
         * For example: JPY 1000.95 get changed to 100095. This need to be 
100000.
         */
        protected function stage_amount() {
-               if ( !$this->getData_Unstaged_Escaped( 'amount' )
-                       || !$this->getData_Unstaged_Escaped( 'currency_code' )
+               if ( !$this->getNormalized( 'amount' )
+                       || !$this->getNormalized( 'currency_code' )
                ) {
                        //can't do anything with amounts at all. Just go home.
                        unset( $this->staged_data['amount'] );
                        return;
                }
 
-               $amount = $this->getData_Unstaged_Escaped( 'amount' );
-               if ( !DataValidator::is_fractional_currency( 
$this->getData_Unstaged_Escaped( 'currency_code' ) ) ) {
+               $amount = $this->getNormalized( 'amount' );
+               if ( !DataValidator::is_fractional_currency( 
$this->getNormalized( 'currency_code' ) ) ) {
                        $amount = floor( $amount );
                }
 
@@ -2130,7 +2135,7 @@
                }
 
                //country-based zip grooming to make AVS (marginally) happy
-               switch ($this->getData_Unstaged_Escaped( 'country' ) ){
+               switch ($this->getNormalized( 'country' ) ){
                        case 'CA':
                                //Canada goes "A0A 0A0"
                                $this->staged_data['zip'] = strtoupper( 
$this->unstaged_data['zip'] );
@@ -2331,7 +2336,7 @@
                );
 
                foreach ($keys as $key){
-                       $msg .= $this->getData_Unstaged_Escaped( $key ) . ', ';
+                       $msg .= $this->getNormalized( $key ) . ', ';
                }
 
                $txn_message = $this->getTransactionMessage();

-- 
To view, visit https://gerrit.wikimedia.org/r/190484
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f541dff43cb168466b3fe4a98524615cb93f0b2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to