jenkins-bot has submitted this change and it was merged.

Change subject: Rationalize accesibility of fns and methods for Extras
......................................................................


Rationalize accesibility of fns and methods for Extras

Oh hey, TestingAccessWrapper can do dumb static tricks!

Change-Id: Ie3d02718a21774b5e445e8e930ea37e8b33ead8d
---
M extras/FraudFilter.php
M extras/conversion_log/conversion_log.body.php
M extras/custom_filters/custom_filters.body.php
M extras/custom_filters/filters/functions/functions.body.php
M extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
M extras/custom_filters/filters/minfraud/minfraud.body.php
M extras/custom_filters/filters/referrer/referrer.body.php
M extras/custom_filters/filters/source/source.body.php
M extras/extras.body.php
M tests/DonationInterfaceTestCase.php
10 files changed, 81 insertions(+), 71 deletions(-)

Approvals:
  Cdentinger: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extras/FraudFilter.php b/extras/FraudFilter.php
index e6755d8..c3d6e21 100644
--- a/extras/FraudFilter.php
+++ b/extras/FraudFilter.php
@@ -10,7 +10,7 @@
         */
        protected $fraud_logger;
 
-       public function __construct( GatewayType $gateway_adapter ) {
+       protected function __construct( GatewayType $gateway_adapter ) {
                parent::__construct( $gateway_adapter );
                $this->fraud_logger = DonationLoggerFactory::getLogger( 
$this->gateway_adapter, '_fraud' );
        }
diff --git a/extras/conversion_log/conversion_log.body.php 
b/extras/conversion_log/conversion_log.body.php
index 585dfaa..1a97ab4 100644
--- a/extras/conversion_log/conversion_log.body.php
+++ b/extras/conversion_log/conversion_log.body.php
@@ -2,12 +2,12 @@
 
 class Gateway_Extras_ConversionLog extends Gateway_Extras {
 
-       public static $instance;
+       protected static $instance;
 
        /**
         * Logs the response from a transaction
         */
-       public function post_process() {
+       protected function post_process() {
                // if the trxn has been outright rejected, log it
                if ( $this->gateway_adapter->getValidationAction() == 'reject' 
) {
                        $this->log(
@@ -33,7 +33,7 @@
                return true;
        }
 
-       static function onPostProcess( GatewayType $gateway_adapter ) {
+       public static function onPostProcess( GatewayType $gateway_adapter ) {
                if ( !$gateway_adapter->getGlobal( 'EnableConversionLog' ) ) {
                        return true;
                }
@@ -41,7 +41,7 @@
                return self::singleton( $gateway_adapter )->post_process();
        }
 
-       static function singleton( GatewayType $gateway_adapter ) {
+       protected static function singleton( GatewayType $gateway_adapter ) {
                if ( !self::$instance ) {
                        self::$instance = new self( $gateway_adapter );
                }
diff --git a/extras/custom_filters/custom_filters.body.php 
b/extras/custom_filters/custom_filters.body.php
index 5546f1e..aa03e6b 100644
--- a/extras/custom_filters/custom_filters.body.php
+++ b/extras/custom_filters/custom_filters.body.php
@@ -20,14 +20,14 @@
         * Define the action to take for a given $risk_score
         * @var array
         */
-       public $action_ranges;
+       protected $action_ranges;
 
        /**
         * A container for an instance of self
         */
-       static $instance;
+       protected static $instance;
 
-       public function __construct( GatewayType $gateway_adapter ) {
+       protected function __construct( GatewayType $gateway_adapter ) {
                parent::__construct( $gateway_adapter ); //gateway_adapter is 
set in there. 
                // load user action ranges and risk score               
                $this->action_ranges = $this->gateway_adapter->getGlobal( 
'CustomFiltersActionRanges' );
@@ -43,7 +43,7 @@
         *
         * @return string The action to take
         */
-       public function determineAction() {
+       protected function determineAction() {
                $risk_score = $this->getRiskScore();
                // possible risk scores are between 0 and 100
                if ( $risk_score < 0 )
@@ -76,7 +76,7 @@
                $this->fraud_logger->info( '"addRiskScore" ' . $log_message );
                $this->risk_score[$source] = $score;
        }
-
+       
 
        /**
         * Add up the risk scores in an array, by default $this->risk_score
@@ -108,8 +108,10 @@
 
        /**
         * Run the transaction through the custom filters
+        * @param string $hook Run custom filters attached to a hook with this 
name
+        * @return bool
         */
-       public function validate( $hook ) {
+       protected function validate( $hook ) {
                // expose a hook for custom filters
                WmfFramework::runHooks( $hook, array( $this->gateway_adapter, 
$this ) );
                $score = $this->getRiskScore();
@@ -172,7 +174,7 @@
                return false;
        }
 
-       static function onValidate( GatewayType $gateway_adapter ) {
+       public static function onValidate( GatewayType $gateway_adapter ) {
                if ( !$gateway_adapter->getGlobal( 'EnableCustomFilters' ) ){
                        return true;
                }
@@ -180,7 +182,7 @@
                return self::singleton( $gateway_adapter )->validate( 
'GatewayCustomFilter' );
        }
 
-       static function onGatewayReady( GatewayType $gateway_adapter ) {
+       public static function onGatewayReady( GatewayType $gateway_adapter ) {
                if ( !$gateway_adapter->getGlobal( 'EnableCustomFilters' ) ){
                        return true;
                }
@@ -188,7 +190,7 @@
                return self::singleton( $gateway_adapter )->validate( 
'GatewayInitialFilter' );
        }
 
-       static function singleton( GatewayType $gateway_adapter ) {
+       protected static function singleton( GatewayType $gateway_adapter ) {
                if ( !self::$instance || $gateway_adapter->isBatchProcessor() ) 
{
                        self::$instance = new self( $gateway_adapter );
                }
diff --git a/extras/custom_filters/filters/functions/functions.body.php 
b/extras/custom_filters/filters/functions/functions.body.php
index a25c9ca..e316d78 100644
--- a/extras/custom_filters/filters/functions/functions.body.php
+++ b/extras/custom_filters/filters/functions/functions.body.php
@@ -6,15 +6,15 @@
         * Container for an instance of self
         * @var Gateway_Extras_CustomFilters_Functions
         */
-       static $instance;
+       protected static $instance;
 
        /**
         * Custom filter object holder
         * @var Gateway_Extras_CustomFilters
         */
-       public $cfo;
+       protected $cfo;
 
-       public function __construct(
+       protected function __construct(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
@@ -28,7 +28,7 @@
         *                                 global variable with name
         * @return bool
         */
-       public function filter( $filterListGlobal ) {
+       protected function filter( $filterListGlobal ) {
                $functions = $this->gateway_adapter->getGlobal( 
$filterListGlobal );
 
                if (
@@ -60,7 +60,7 @@
                return TRUE;
        }
 
-       static function onFilter(
+       public static function onFilter(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
@@ -70,7 +70,7 @@
                );
        }
 
-       static function onInitialFilter(
+       public static function onInitialFilter(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
@@ -80,7 +80,7 @@
                );
        }
 
-       static function singleton(
+       protected static function singleton(
                GatewayType $gateway_adapter,
                $custom_filter_object
        ) {
diff --git a/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php 
b/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
index e99a532..b03e1f5 100644
--- a/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
+++ b/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php
@@ -6,13 +6,13 @@
         * Container for an instance of self
         * @var Gateway_Extras_CustomFilters_IP_Velocity
         */
-       static $instance;
+       protected static $instance;
 
        /**
         * Custom filter object holder
         * @var Gateway_Extras_CustomFilters
         */
-       public $cfo;
+       protected $cfo;
 
        /**
         * Memcached instance we use to store and retrieve scores
@@ -20,7 +20,7 @@
         */
        protected $cache_obj;
 
-       public function __construct(
+       protected function __construct(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object = null
        ) {
@@ -29,7 +29,7 @@
                $this->cfo = $custom_filter_object;
        }
 
-       public function filter() {
+       protected function filter() {
                $user_ip = $this->gateway_adapter->getData_Unstaged_Escaped( 
'user_ip' );
                
                //first, handle the whitelist / blacklist before you do 
anything else. 
@@ -71,17 +71,17 @@
                //fail open, in case memcached doesn't work.
                return true;
        }
-       
-       
-       public function postProcess(){
+
+
+       protected function postProcess(){
                //after a successful transaction, add a record of it.
                if ( $this->connectToMemcache() ){
                        $this->addNowToMemcachedValue();
                }
                return true;
        }
-       
-       function connectToMemcache(){
+
+       protected function connectToMemcache(){
                //this needs Memcached to work.
                if ( !class_exists('Memcached') ){
                        $this->gateway_logger->alert( "IPVelocityFilter says 
Memcached class does not exist." );
@@ -98,8 +98,8 @@
                        return false;
                }
        }
-       
-       function getMemcachedValue(){           
+
+       protected function getMemcachedValue(){
                //check to see if the user ip is in memcache
                //need to be connected first. 
                $user_ip = $this->gateway_adapter->getData_Unstaged_Escaped( 
'user_ip' );
@@ -117,7 +117,7 @@
         * @param bool $fail If this entry was added on the filter being tripped
         * @param bool $toxic If we're adding this entry to penalize a toxic 
card
         */
-       function addNowToMemcachedValue( $oldvalue = null, $fail = false, 
$toxic = false ){
+       protected function addNowToMemcachedValue( $oldvalue = null, $fail = 
false, $toxic = false ){
                //need to be connected first. 
                if ( is_null( $oldvalue ) ){
                        $oldvalue = $this->getMemcachedValue();
@@ -140,9 +140,9 @@
                        $this->gateway_logger->alert( "IPVelocityFilter unable 
to set new memcache data." );
                }
        }
-       
-       
-       static function addNowToVelocityData( $stored = false, $timeout = false 
){
+
+
+       protected static function addNowToVelocityData( $stored = false, 
$timeout = false ){
                $new_velocity_records = array();
                $nowstamp = time();
                if ( is_array( $stored ) ){
@@ -165,7 +165,7 @@
         * @param Gateway_Extras_CustomFilters $custom_filter_object
         * @return bool
         */
-       static function onFilter( $gateway_adapter, $custom_filter_object ) {
+       public static function onFilter( $gateway_adapter, 
$custom_filter_object ) {
                if ( !$gateway_adapter->getGlobal( 'EnableIPVelocityFilter' ) ){
                        return true;
                }
@@ -186,7 +186,7 @@
         * @param Gateway_Extras_CustomFilters $custom_filter_object
         * @return bool
         */
-       static function onInitialFilter( $gateway_adapter, 
$custom_filter_object ) {
+       public static function onInitialFilter( $gateway_adapter, 
$custom_filter_object ) {
                if ( !$gateway_adapter->getGlobal( 'EnableIPVelocityFilter' ) ){
                        return true;
                }
@@ -199,7 +199,7 @@
                return self::singleton( $gateway_adapter, $custom_filter_object 
)->filter();
        }
 
-       static function onPostProcess( GatewayType $gateway_adapter ) {
+       public static function onPostProcess( GatewayType $gateway_adapter ) {
                if ( !$gateway_adapter->getGlobal( 'EnableIPVelocityFilter' ) ){
                        return true;
                }
@@ -207,7 +207,7 @@
                return self::singleton( $gateway_adapter )->postProcess();
        }
 
-       static function singleton(
+       protected static function singleton(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object = null
        ) {
diff --git a/extras/custom_filters/filters/minfraud/minfraud.body.php 
b/extras/custom_filters/filters/minfraud/minfraud.body.php
index 31d724e..ffe920a 100644
--- a/extras/custom_filters/filters/minfraud/minfraud.body.php
+++ b/extras/custom_filters/filters/minfraud/minfraud.body.php
@@ -40,43 +40,43 @@
         * Instance of minFraud CreditCardFraudDetection
         * @var CreditCardFraudDetection $ccfd
         */
-       public $ccfd;
+       protected $ccfd;
 
        /**
         * Instance of Custom filter object
         * @var Gateway_Extras_CustomFilters $cfo
         */
-       public $cfo;
+       protected $cfo;
 
        /**
         * The query to send to minFraud
         * @var array $minfraudQuery
         */
-       public $minfraudQuery = array();
+       protected $minfraudQuery = array();
 
        /**
         * Full response from minFraud
         * @var array $minfraudResponse
         */
-       public $minfraudResponse = array();
+       protected $minfraudResponse = array();
 
        /**
         * An array of minFraud API servers
         * @var array $minFraudServers
         */
-       public $minFraudServers = array();
+       protected $minFraudServers = array();
 
        /**
         * License key for minfraud
         * @var string $minfraudLicenseKey
         */
-       public $minfraudLicenseKey = '';
+       protected $minfraudLicenseKey = '';
        
        /**
         * Instance of Gateway_Extras_CustomFilters_MinFraud
         * @var Gateway_Extras_CustomFilters_MinFraud $instance
         */
-       public static $instance;
+       protected static $instance;
 
        /**
         * Sends messages to the blah_gateway_fraud log
@@ -98,7 +98,7 @@
         * @param string            $license_key        The license key. May 
also be set in $wgMinFraudLicenseKey
         * @throws RuntimeException
         */
-       public function __construct(
+       protected function __construct(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object,
                $license_key = NULL
@@ -150,7 +150,7 @@
         * @param array $data
         * @return array containing hash for minfraud query
         */
-       public function build_query( array $data ) {
+       protected function build_query( array $data ) {
                // mapping of data keys -> minfraud array keys
                $map = array(
                        "city" => "city",
@@ -223,7 +223,7 @@
         *
         * @return boolean
         */
-       public function can_bypass_minfraud() {
+       protected function can_bypass_minfraud() {
                // if the data bits data_hash and action are not set, we need 
to hit minFraud
                $localdata = $this->gateway_adapter->getData_Unstaged_Escaped();
                if ( !isset($localdata['data_hash']) || !strlen( 
$localdata['data_hash'] ) || !isset($localdata['action']) || !strlen( 
$localdata['action'] ) ) {
@@ -261,7 +261,7 @@
         *
         * @return bool true
         */
-       public function filter() {
+       protected function filter() {
                // see if we can bypass minfraud
                if ( $this->can_bypass_minfraud() ){
                        return TRUE;
@@ -295,7 +295,7 @@
         * Get instance of CreditCardFraudDetection
         * @return CreditCardFraudDetection
         */
-       public function get_ccfd() {
+       protected function get_ccfd() {
                if ( !$this->ccfd ) {
                        $this->ccfd = new CreditCardFraudDetection();
                        
@@ -316,7 +316,7 @@
         *
         * @see 
http://svn.wikimedia.org/viewvc/wikimedia/trunk/fundraising-misc/minfraud_log_mailer/
         */
-       public function log_query() {
+       protected function log_query() {
 
                $encoded_response = array();
                foreach ($this->minfraudResponse as $key => $value) {
@@ -358,7 +358,7 @@
         *
         * @param array $minfraud_query The array you would pass to minfraud in 
a query
         */
-       public function query_minfraud( array $minfraud_query ) {
+       protected function query_minfraud( array $minfraud_query ) {
                global $wgMinFraudTimeout;
                $ccfd = $this->get_ccfd();
                $ccfd->timeout = $wgMinFraudTimeout;
@@ -382,7 +382,7 @@
         *
         * @return Gateway_Extras_CustomFilters_MinFraud
         */
-       public static function singleton(
+       protected static function singleton(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
diff --git a/extras/custom_filters/filters/referrer/referrer.body.php 
b/extras/custom_filters/filters/referrer/referrer.body.php
index 0e094b0..0c62ad4 100644
--- a/extras/custom_filters/filters/referrer/referrer.body.php
+++ b/extras/custom_filters/filters/referrer/referrer.body.php
@@ -6,15 +6,15 @@
         * Container for an instance of self
         * @var Gateway_Extras_CustomFilters_Referrer
         */
-       static $instance;
+       protected static $instance;
 
        /**
         * Custom filter object holder
         * @var Gateway_Extras_CustomFilters
         */
-       public $cfo;
+       protected $cfo;
 
-       public function __construct(
+       protected function __construct(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
@@ -23,7 +23,7 @@
                $this->cfo = $custom_filter_object;
        }
 
-       public function filter() {
+       protected function filter() {
                // pull out the referrer from the gateway_adapter
                $referrer = $this->gateway_adapter->getData_Unstaged_Escaped( 
'referrer' );
 
@@ -64,7 +64,7 @@
                return self::singleton( $gateway_adapter, $custom_filter_object 
)->filter();
        }
 
-       static function singleton(
+       protected static function singleton(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
diff --git a/extras/custom_filters/filters/source/source.body.php 
b/extras/custom_filters/filters/source/source.body.php
index 046babb..c53d3d8 100644
--- a/extras/custom_filters/filters/source/source.body.php
+++ b/extras/custom_filters/filters/source/source.body.php
@@ -6,15 +6,15 @@
         * Container for an instance of self
         * @var Gateway_Extras_CustomFilters_Source
         */
-       static $instance;
+       protected static $instance;
 
        /**
         * Custom filter object holder
         * @var Gateway_Extras_CustomFilters
         */
-       public $cfo;
+       protected $cfo;
 
-       public function __construct(
+       protected function __construct(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
@@ -23,7 +23,7 @@
                $this->cfo = $custom_filter_object;
        }
 
-       public function filter() {
+       protected function filter() {
                // pull out the source from the filter object
                $source = $this->gateway_adapter->getData_Unstaged_Escaped( 
'utm_source' );
 
@@ -63,7 +63,7 @@
                return self::singleton( $gateway_adapter, $custom_filter_object 
)->filter();
        }
 
-       static function singleton(
+       protected static function singleton(
                GatewayType $gateway_adapter,
                Gateway_Extras_CustomFilters $custom_filter_object
        ) {
diff --git a/extras/extras.body.php b/extras/extras.body.php
index 1736532..b88c6a4 100644
--- a/extras/extras.body.php
+++ b/extras/extras.body.php
@@ -9,7 +9,7 @@
        /**
         * @var GatewayType
         */
-       public $gateway_adapter;
+       protected $gateway_adapter;
 
        /**
         * Sends messages to the blah_gateway_trxn log
@@ -23,7 +23,7 @@
         */
        protected $gateway_logger;
 
-       public function __construct( GatewayType $gateway_adapter ) {
+       protected function __construct( GatewayType $gateway_adapter ) {
                $this->gateway_adapter = $gateway_adapter;
                $this->transaction_logger = DonationLoggerFactory::getLogger( 
$this->gateway_adapter, '_trxn' );
                $this->gateway_logger = DonationLoggerFactory::getLogger( 
$this->gateway_adapter );
@@ -38,7 +38,7 @@
         * @param string $data
         * @param string $log_level One of the constants defined in @see 
\Psr\Log\LogLevel
         */
-       public function log( $id = '', $status = '', $data = '', $log_level = 
LogLevel::INFO ) {
+       protected function log( $id = '', $status = '', $data = '', $log_level 
= LogLevel::INFO ) {
 
                // format the message
                $msg = '"' . date( 'c' ) . '"';
@@ -57,7 +57,7 @@
         * @param string $data the data to hash
         * @return string The hash of the data
         */
-       public function generate_hash( $data ) {
+       protected function generate_hash( $data ) {
                $salt = $this->gateway_adapter->getGlobal( 'Salt' );
                return hash( "sha512", $salt . $data );
        }
@@ -68,7 +68,7 @@
         * @param string $data The data to hash and compare to $hash
         * @return bool
         */
-       public function compare_hash( $hash, $data ) {
+       protected function compare_hash( $hash, $data ) {
                if ( $hash === $this->generate_hash( $data ) ) {
                        return TRUE;
                }
diff --git a/tests/DonationInterfaceTestCase.php 
b/tests/DonationInterfaceTestCase.php
index 4fca50f..b8843b0 100644
--- a/tests/DonationInterfaceTestCase.php
+++ b/tests/DonationInterfaceTestCase.php
@@ -500,7 +500,15 @@
                        'Gateway_Extras_SessionVelocityFilter',
                );
                foreach( $singleton_classes as $singleton_class ) {
-                       $singleton_class::$instance = null;
+                       if ( method_exists( 'TestingAccessWrapper', 
'newFromClass' ) ) {
+                               // In 1.27, we have official static support
+                               $unwrapped = 
TestingAccessWrapper::newFromClass( $singleton_class );
+                       } else {
+                               // This static-as-instance voodoo shouldn't 
work, but the
+                               // ReflectionClass used in TestingAccessWrapper 
is very obliging
+                               $unwrapped = 
TestingAccessWrapper::newFromObject( $singleton_class );
+                       }
+                       $unwrapped->instance = null; // more cheating
                }
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3d02718a21774b5e445e8e930ea37e8b33ead8d
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to