Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/290982
Change subject: Rationalize accesibility of fns and methods for Extras ...................................................................... Rationalize accesibility of fns and methods for Extras TODO: ip_velocity 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/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 9 files changed, 56 insertions(+), 51 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/82/290982/1 diff --git a/extras/FraudFilter.php b/extras/FraudFilter.php index b183f7c..34d99dd 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 146043e..0f41a26 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 ) @@ -101,8 +101,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(); @@ -134,7 +136,7 @@ return TRUE; } - static function onValidate( GatewayType $gateway_adapter ) { + public static function onValidate( GatewayType $gateway_adapter ) { if ( !$gateway_adapter->getGlobal( 'EnableCustomFilters' ) ){ return true; } @@ -142,7 +144,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; } @@ -150,7 +152,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/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..4080036 100644 --- a/tests/DonationInterfaceTestCase.php +++ b/tests/DonationInterfaceTestCase.php @@ -500,7 +500,10 @@ 'Gateway_Extras_SessionVelocityFilter', ); foreach( $singleton_classes as $singleton_class ) { - $singleton_class::$instance = null; + // 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; } } -- To view, visit https://gerrit.wikimedia.org/r/290982 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie3d02718a21774b5e445e8e930ea37e8b33ead8d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits