r103970 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103969‎ | r103970 | r103971 >
Date:22:48, 22 November 2011
Author:jpostlethwaite
Status:ok
Tags:
Comment:
Converting $code to an integer if it is numeric in findCodeAction().
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -1377,18 +1377,41 @@
13781378 }
13791379 }
13801380
1381 - function findCodeAction( $transaction, $key, $code ) {
 1381+ /**
 1382+ * findCodeAction
 1383+ *
 1384+ * @param string $transaction
 1385+ * @param string $key The key to lookup in the transaction such as STATUSID
 1386+ * @param integer|string $code This gets converted to an integer if the values is numeric.
 1387+ *
 1388+ * @return null|string Returns the code action if a valid code is supplied. Otherwise, the return is null.
 1389+ */
 1390+ public function findCodeAction( $transaction, $key, $code ) {
 1391+
13821392 $this->getStopwatch( __FUNCTION__, true );
1383 - if ( !array_key_exists( $transaction, $this->return_value_map ) || !array_key_exists( $key, $this->return_value_map[$transaction] ) ) {
 1393+
 1394+ // Do not allow anything that is not numeric
 1395+ if ( !is_numeric( $code ) ) {
13841396 return null;
13851397 }
1386 - if ( !is_array( $this->return_value_map[$transaction][$key] ) ) {
 1398+
 1399+ // Cast the code as an integer
 1400+ settype( $code, 'integer');
 1401+
 1402+ // Check to see if the transaction is defined
 1403+ if ( !array_key_exists( $transaction, $this->return_value_map ) ) {
13871404 return null;
13881405 }
 1406+
 1407+ // Verify the key exists within the transaction
 1408+ if ( !array_key_exists( $key, $this->return_value_map[ $transaction ] ) || !is_array( $this->return_value_map[ $transaction ][ $key ] ) ) {
 1409+ return null;
 1410+ }
 1411+
13891412 //sort the array so we can do this quickly.
1390 - ksort( $this->return_value_map[$transaction][$key], SORT_NUMERIC );
 1413+ ksort( $this->return_value_map[ $transaction ][ $key ], SORT_NUMERIC );
13911414
1392 - $ranges = $this->return_value_map[$transaction][$key];
 1415+ $ranges = $this->return_value_map[ $transaction ][ $key ];
13931416 //so, you have a code, which is a number. You also have a numerically sorted array.
13941417 //loop through until you find an upper >= your code.
13951418 //make sure it's in the range, and return the action.

Follow-up revisions

RevisionCommit summaryAuthorDate
r104724MFT r103970, r104071, r104224, r104717, r104718khorn19:30, 30 November 2011

Status & tagging log