Remove "$that" from SessionManager
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 10 Feb 2016 17:10:38 +0000 (12:10 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 10 Feb 2016 17:10:38 +0000 (12:10 -0500)
Also "function () use ( &$ref )" that was being done for similar
reasons.

Change-Id: If4ec263a9a9c02c1c6a414b26a0e77ba144437f1

includes/session/SessionBackend.php
tests/phpunit/includes/session/CookieSessionProviderTest.php
tests/phpunit/includes/session/SessionManagerTest.php

index a79c5cb..fe446e3 100644 (file)
@@ -549,13 +549,11 @@ final class SessionBackend {
         * @return \ScopedCallback When this goes out of scope, a save will be triggered
         */
        public function delaySave() {
-               $that = $this;
                $this->delaySave++;
-               $ref = &$this->delaySave;
-               return new \ScopedCallback( function () use ( $that, &$ref ) {
-                       if ( --$ref <= 0 ) {
-                               $ref = 0;
-                               $that->save();
+               return new \ScopedCallback( function () {
+                       if ( --$this->delaySave <= 0 ) {
+                               $this->delaySave = 0;
+                               $this->save();
                        }
                } );
        }
@@ -692,9 +690,8 @@ final class SessionBackend {
        private function checkPHPSession() {
                if ( !$this->checkPHPSessionRecursionGuard ) {
                        $this->checkPHPSessionRecursionGuard = true;
-                       $ref = &$this->checkPHPSessionRecursionGuard;
-                       $reset = new \ScopedCallback( function () use ( &$ref ) {
-                               $ref = false;
+                       $reset = new \ScopedCallback( function () {
+                               $this->checkPHPSessionRecursionGuard = false;
                        } );
 
                        if ( $this->usePhpSessionHandling && session_id() === '' && PHPSessionHandler::isEnabled() &&
index f5c8b05..659826f 100644 (file)
@@ -568,8 +568,6 @@ class CookieSessionProviderTest extends MediaWikiTestCase {
        }
 
        public function testPersistSessionWithHook() {
-               $that = $this;
-
                $provider = new CookieSessionProvider( array(
                        'priority' => 1,
                        'sessionName' => 'MySessionName',
@@ -620,14 +618,14 @@ class CookieSessionProviderTest extends MediaWikiTestCase {
                // Logged-in user, no remember
                $mock = $this->getMock( __CLASS__, array( 'onUserSetCookies' ) );
                $mock->expects( $this->once() )->method( 'onUserSetCookies' )
-                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $that, $user ) {
-                               $that->assertSame( $user, $u );
-                               $that->assertEquals( array(
+                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) {
+                               $this->assertSame( $user, $u );
+                               $this->assertEquals( array(
                                        'wsUserID' => $user->getId(),
                                        'wsUserName' => $user->getName(),
                                        'wsToken' => $user->getToken(),
                                ), $sessionData );
-                               $that->assertEquals( array(
+                               $this->assertEquals( array(
                                        'UserID' => $user->getId(),
                                        'UserName' => $user->getName(),
                                        'Token' => false,
@@ -663,14 +661,14 @@ class CookieSessionProviderTest extends MediaWikiTestCase {
                // Logged-in user, remember
                $mock = $this->getMock( __CLASS__, array( 'onUserSetCookies' ) );
                $mock->expects( $this->once() )->method( 'onUserSetCookies' )
-                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $that, $user ) {
-                               $that->assertSame( $user, $u );
-                               $that->assertEquals( array(
+                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) {
+                               $this->assertSame( $user, $u );
+                               $this->assertEquals( array(
                                        'wsUserID' => $user->getId(),
                                        'wsUserName' => $user->getName(),
                                        'wsToken' => $user->getToken(),
                                ), $sessionData );
-                               $that->assertEquals( array(
+                               $this->assertEquals( array(
                                        'UserID' => $user->getId(),
                                        'UserName' => $user->getName(),
                                        'Token' => $user->getToken(),
index 6be8957..16beb72 100644 (file)
@@ -760,8 +760,6 @@ class SessionManagerTest extends MediaWikiTestCase {
        public function testAutoCreateUser() {
                global $wgGroupPermissions;
 
-               $that = $this;
-
                \ObjectCache::$instances[__METHOD__] = new TestBagOStuff();
                $this->setMwGlobals( array( 'wgMainCacheType' => __METHOD__ ) );
                $this->setMWGlobals( array(
@@ -1012,10 +1010,10 @@ class SessionManagerTest extends MediaWikiTestCase {
                $logger->clearBuffer();
 
                // Sanity check that creation still works, and test completion hook
-               $cb = $this->callback( function ( User $user ) use ( $that ) {
-                       $that->assertNotEquals( 0, $user->getId() );
-                       $that->assertSame( 'UTSessionAutoCreate4', $user->getName() );
-                       $that->assertEquals(
+               $cb = $this->callback( function ( User $user ) {
+                       $this->assertNotEquals( 0, $user->getId() );
+                       $this->assertSame( 'UTSessionAutoCreate4', $user->getName() );
+                       $this->assertEquals(
                                $user->getId(), User::idFromName( 'UTSessionAutoCreate4', User::READ_LATEST )
                        );
                        return true;
@@ -1649,7 +1647,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                $this->assertSame( array(), $logger->getBuffer() );
 
                // Hook
-               $that = $this;
                $called = false;
                $data = array( 'foo' => 1 );
                $this->store->setSession( $id, array( 'metadata' => $metadata, 'data' => $data ) );
@@ -1660,14 +1657,14 @@ class SessionManagerTest extends MediaWikiTestCase {
                ) );
                $this->mergeMwGlobalArrayValue( 'wgHooks', array(
                        'SessionCheckInfo' => array( function ( &$reason, $i, $r, $m, $d ) use (
-                               $that, $info, $metadata, $data, $request, &$called
+                               $info, $metadata, $data, $request, &$called
                        ) {
-                               $that->assertSame( $info->getId(), $i->getId() );
-                               $that->assertSame( $info->getProvider(), $i->getProvider() );
-                               $that->assertSame( $info->getUserInfo(), $i->getUserInfo() );
-                               $that->assertSame( $request, $r );
-                               $that->assertEquals( $metadata, $m );
-                               $that->assertEquals( $data, $d );
+                               $this->assertSame( $info->getId(), $i->getId() );
+                               $this->assertSame( $info->getProvider(), $i->getProvider() );
+                               $this->assertSame( $info->getUserInfo(), $i->getUserInfo() );
+                               $this->assertSame( $request, $r );
+                               $this->assertEquals( $metadata, $m );
+                               $this->assertEquals( $data, $d );
                                $called = true;
                                return false;
                        } )