r114344 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114343‎ | r114344 | r114345 >
Date:03:36, 21 March 2012
Author:demon
Status:resolved (Comments)
Tags:
Comment:
Resolve issues with r109666: mixing getters and setters in the same function is confusing, so split it in 2. Also removes isset() to check for null
Modified paths:
  • /trunk/extensions/InterfaceConcurrency/ApiConcurrency.php (modified) (history)
  • /trunk/extensions/InterfaceConcurrency/includes/ConcurrencyCheck.php (modified) (history)
  • /trunk/extensions/InterfaceConcurrency/tests/phpunit/ConcurrencyCheckTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/InterfaceConcurrency/tests/phpunit/ConcurrencyCheckTest.php
@@ -59,7 +59,7 @@
6060
6161 // tests
6262 $this->assertTrue( $first->checkout( $testKey ), "Initial checkout" );
63 - $res = $first->checkoutResult();
 63+ $res = $first->getCheckoutResult();
6464 $this->assertEquals( $firstId, $res['userId'], "User matches on success");
6565 $this->assertTrue( array_key_exists( 'expiration', $res ), "Expiration is present");
6666 $this->assertTrue( $res['expiration'] > 0, "Expiration is a positive integer");
@@ -71,7 +71,7 @@
7272 $wgMemc->delete($cacheKey);
7373 $first->lastCheckout = array();
7474 $this->assertTrue( $first->checkout( $testKey ), "Cache miss" );
75 - $res = $first->checkoutResult();
 75+ $res = $first->getCheckoutResult();
7676 $this->assertEquals( $firstId, $res['userId'], "User matches on success (nocache)");
7777 $this->assertTrue( array_key_exists( 'expiration', $res ), "Expiration is present (nocache)");
7878 $this->assertTrue( $res['expiration'] > 0, "Expiration is a positive integer (nocache)");
@@ -80,7 +80,7 @@
8181 $second->checkout( $testKey ),
8282 "Checkout of locked resource fails as different user"
8383 );
84 - $res = $second->checkoutResult();
 84+ $res = $second->getCheckoutResult();
8585 $this->assertEquals( $firstId, $res['userId'], "Actual owner matches on failure");
8686 $this->assertTrue( $res['expiration'] > 0, "Expiration is a positive integer");
8787
Index: trunk/extensions/InterfaceConcurrency/includes/ConcurrencyCheck.php
@@ -72,7 +72,7 @@
7373 $cached['expiration'] > time()
7474 ) {
7575 // this is already checked out.
76 - $this->checkoutResult( $cached );
 76+ $this->setCheckoutResult( $cached );
7777 return false;
7878 }
7979 }
@@ -105,7 +105,7 @@
106106 $wgMemc->set( $cacheKey, $toCache, $this->expirationTime );
107107
108108 $dbw->commit( __METHOD__ );
109 - $this->checkoutResult( $toCache );
 109+ $this->setCheckoutResult( $toCache );
110110 return true;
111111 }
112112
@@ -145,7 +145,7 @@
146146 );
147147
148148 $dbw->rollback( __METHOD__ );
149 - $this->checkoutResult( $toCache );
 149+ $this->setCheckoutResult( $toCache );
150150 return false;
151151 }
152152
@@ -172,7 +172,7 @@
173173 );
174174
175175 $dbw->commit( __METHOD__ );
176 - $this->checkoutResult( $toCache );
 176+ $this->setCheckoutResult( $toCache );
177177 return true;
178178 }
179179
@@ -401,15 +401,22 @@
402402 /**
403403 * Return information about the owner of the record on which a checkout was last
404404 * attempted.
 405+ *
 406+ * @return array
 407+ */
 408+ public function getCheckoutResult() {
 409+ return $this->lastCheckout;
 410+ }
 411+
 412+ /**
 413+ * Set information about the owner of the record on which a checkout was last
 414+ * attempted.
405415 *
406416 * @param $checkoutInfo array (optional) of checkout information to store
407417 * @return array
408418 */
409 - public function checkoutResult( $checkoutInfo = null ) {
410 - if( isset( $checkoutInfo ) ) { // true on empty array
411 - $this->lastCheckout = $checkoutInfo;
412 - }
413 - return $this->lastCheckout;
 419+ protected function setCheckoutResult( $checkoutInfo = array() ) {
 420+ $this->lastCheckout = $checkoutInfo;
414421 }
415422
416423 /**
Index: trunk/extensions/InterfaceConcurrency/ApiConcurrency.php
@@ -30,7 +30,7 @@
3131
3232 // data to be utilized by the caller for checkout
3333 if ( $params['ccaction'] === 'checkout' ) {
34 - $lastCheckout = $concurrencyCheck->checkoutResult();
 34+ $lastCheckout = $concurrencyCheck->getCheckoutResult();
3535
3636 if ( $res['result'] === 'success' ) {
3737 $user = $wgUser;

Follow-up revisions

RevisionCommit summaryAuthorDate
r114368Follow-up r114344: fixed outdated comment, removed a couple of unused varsmaxsem13:51, 21 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109666added checkoutResult() for generating more informative user-facing errorsraindrift00:11, 21 January 2012

Comments

#Comment by Kaldari (talk | contribs)   07:57, 21 March 2012

The comments for setCheckoutResult() says that it returns an array, but it actually returns nothing. It should either be set to return true or the @return comment should be removed.

#Comment by MaxSem (talk | contribs)   13:52, 21 March 2012

Fixed in r114368.

Status & tagging log