From: jenkins-bot Date: Wed, 10 Feb 2016 19:42:24 +0000 (+0000) Subject: Merge "resourceloader: Remove obsolete '$that = $this' closure pattern" X-Git-Tag: 1.31.0-rc.0~8012 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=73e21844a3f437532c7f353a5ff67d6a3178b075;hp=f9b4a217e9b652ef12ce5e826d594d207d1af8d8;p=lhc%2Fweb%2Fwiklou.git Merge "resourceloader: Remove obsolete '$that = $this' closure pattern" --- diff --git a/includes/Title.php b/includes/Title.php index 55c7179276..50721afd42 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -161,9 +161,9 @@ class Title implements LinkTarget { * Avoid usage of this singleton by using TitleValue * and the associated services when possible. * - * @return TitleParser + * @return MediaWikiTitleCodec */ - private static function getTitleParser() { + private static function getMediaWikiTitleCodec() { global $wgContLang, $wgLocalInterwikis; static $titleCodec = null; @@ -200,9 +200,9 @@ class Title implements LinkTarget { * @return TitleFormatter */ private static function getTitleFormatter() { - // NOTE: we know that getTitleParser() returns a MediaWikiTitleCodec, + // NOTE: we know that getMediaWikiTitleCodec() returns a MediaWikiTitleCodec, // which implements TitleFormatter. - return self::getTitleParser(); + return self::getMediaWikiTitleCodec(); } function __construct() { @@ -3353,7 +3353,7 @@ class Title implements LinkTarget { // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share // the parsing code with Title, while avoiding massive refactoring. // @todo: get rid of secureAndSplit, refactor parsing code. - $titleParser = self::getTitleParser(); + $titleParser = self::getMediaWikiTitleCodec(); // MalformedTitleException can be thrown here $parts = $titleParser->splitTitleString( $dbkey, $this->getDefaultNamespace() ); diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index f8192e5cca..eb76024f7a 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1181,27 +1181,44 @@ class ApiMain extends ApiBase { && in_array( 'bot', $this->getUser()->getGroups() ) && wfGetLB()->getServerCount() > 1 ) { - // Figure out how many servers have passed the lag threshold - $numLagged = 0; - $lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' ); - foreach ( wfGetLB()->getLagTimes() as $lag ) { - if ( $lag > $lagLimit ) { - ++$numLagged; - } - } - // If a majority of slaves are too lagged then disallow writes - $slaveCount = wfGetLB()->getServerCount() - 1; - if ( $numLagged >= ceil( $slaveCount / 2 ) ) { - $parsed = $this->parseMsg( array( 'readonlytext' ) ); - $this->dieUsage( - $parsed['info'], - $parsed['code'], - /* http error */ - 0, - array( 'readonlyreason' => "Waiting for $numLagged lagged database(s)" ) - ); + $this->checkBotReadOnly(); + } + } + + /** + * Check whether we are readonly for bots + */ + private function checkBotReadOnly() { + // Figure out how many servers have passed the lag threshold + $numLagged = 0; + $lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' ); + $laggedServers = array(); + $loadBalancer = wfGetLB(); + foreach ( $loadBalancer->getLagTimes() as $serverIndex => $lag ) { + if ( $lag > $lagLimit ) { + ++$numLagged; + $laggedServers[] = $loadBalancer->getServerName( $serverIndex ) . " ({$lag}s)"; } } + + // If a majority of slaves are too lagged then disallow writes + $slaveCount = wfGetLB()->getServerCount() - 1; + if ( $numLagged >= ceil( $slaveCount / 2 ) ) { + $laggedServers = join( ', ', $laggedServers ); + wfDebugLog( + 'api-readonly', + "Api request failed as read only because the following DBs are lagged: $laggedServers" + ); + + $parsed = $this->parseMsg( array( 'readonlytext' ) ); + $this->dieUsage( + $parsed['info'], + $parsed['code'], + /* http error */ + 0, + array( 'readonlyreason' => "Waiting for $numLagged lagged database(s)" ) + ); + } } /** diff --git a/includes/api/ApiMessage.php b/includes/api/ApiMessage.php index 5c3434f95c..f24a7cc470 100644 --- a/includes/api/ApiMessage.php +++ b/includes/api/ApiMessage.php @@ -63,15 +63,57 @@ interface IApiMessage extends MessageSpecifier { public function setApiData( array $data ); } +/** + * Trait to implement the IApiMessage interface for Message subclasses + * @since 1.27 + * @ingroup API + */ +trait ApiMessageTrait { + protected $apiCode = null; + protected $apiData = array(); + + public function getApiCode() { + return $this->apiCode === null ? $this->getKey() : $this->apiCode; + } + + public function setApiCode( $code, array $data = null ) { + $this->apiCode = $code; + if ( $data !== null ) { + $this->setApiData( $data ); + } + } + + public function getApiData() { + return $this->apiData; + } + + public function setApiData( array $data ) { + $this->apiData = $data; + } + + public function serialize() { + return serialize( array( + 'parent' => parent::serialize(), + 'apiCode' => $this->apiCode, + 'apiData' => $this->apiData, + ) ); + } + + public function unserialize( $serialized ) { + $data = unserialize( $serialized ); + parent::unserialize( $data['parent'] ); + $this->apiCode = $data['apiCode']; + $this->apiData = $data['apiData']; + } +} + /** * Extension of Message implementing IApiMessage * @since 1.25 * @ingroup API - * @todo: Would be nice to use a Trait here to avoid code duplication */ class ApiMessage extends Message implements IApiMessage { - protected $apiCode = null; - protected $apiData = array(); + use ApiMessageTrait; /** * Create an IApiMessage for the message @@ -119,51 +161,15 @@ class ApiMessage extends Message implements IApiMessage { $this->apiCode = $code; $this->apiData = (array)$data; } - - public function getApiCode() { - return $this->apiCode === null ? $this->getKey() : $this->apiCode; - } - - public function setApiCode( $code, array $data = null ) { - $this->apiCode = $code; - if ( $data !== null ) { - $this->setApiData( $data ); - } - } - - public function getApiData() { - return $this->apiData; - } - - public function setApiData( array $data ) { - $this->apiData = $data; - } - - public function serialize() { - return serialize( array( - 'parent' => parent::serialize(), - 'apiCode' => $this->apiCode, - 'apiData' => $this->apiData, - ) ); - } - - public function unserialize( $serialized ) { - $data = unserialize( $serialized ); - parent::unserialize( $data['parent'] ); - $this->apiCode = $data['apiCode']; - $this->apiData = $data['apiData']; - } } /** * Extension of RawMessage implementing IApiMessage * @since 1.25 * @ingroup API - * @todo: Would be nice to use a Trait here to avoid code duplication */ class ApiRawMessage extends RawMessage implements IApiMessage { - protected $apiCode = null; - protected $apiData = array(); + use ApiMessageTrait; /** * @param RawMessage|string|array $msg @@ -189,38 +195,4 @@ class ApiRawMessage extends RawMessage implements IApiMessage { $this->apiCode = $code; $this->apiData = (array)$data; } - - public function getApiCode() { - return $this->apiCode === null ? $this->getKey() : $this->apiCode; - } - - public function setApiCode( $code, array $data = null ) { - $this->apiCode = $code; - if ( $data !== null ) { - $this->setApiData( $data ); - } - } - - public function getApiData() { - return $this->apiData; - } - - public function setApiData( array $data ) { - $this->apiData = $data; - } - - public function serialize() { - return serialize( array( - 'parent' => parent::serialize(), - 'apiCode' => $this->apiCode, - 'apiData' => $this->apiData, - ) ); - } - - public function unserialize( $serialized ) { - $data = unserialize( $serialized ); - parent::unserialize( $data['parent'] ); - $this->apiCode = $data['apiCode']; - $this->apiData = $data['apiData']; - } } diff --git a/includes/db/Database.php b/includes/db/Database.php index a4d0ad0532..564cd2ee24 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1929,10 +1929,7 @@ abstract class DatabaseBase implements IDatabase { * @param string $index * @return string */ - public function indexName( $index ) { - // @FIXME: Make this protected once we move away from PHP 5.3 - // Needs to be public because of usage in closure (in DatabaseBase::replaceVars) - + protected function indexName( $index ) { // Backwards-compatibility hack $renamed = array( 'ar_usertext_timestamp' => 'usertext_timestamp', @@ -3100,7 +3097,6 @@ abstract class DatabaseBase implements IDatabase { * @return string The new SQL statement with variables replaced */ protected function replaceVars( $ins ) { - $that = $this; $vars = $this->getSchemaVars(); return preg_replace_callback( '! @@ -3109,19 +3105,19 @@ abstract class DatabaseBase implements IDatabase { `\{\$ (\w+) }` | # 4. addIdentifierQuotes /\*\$ (\w+) \*/ # 5. leave unencoded !x', - function ( $m ) use ( $that, $vars ) { + function ( $m ) use ( $vars ) { // Note: Because of , // check for both nonexistent keys *and* the empty string. if ( isset( $m[1] ) && $m[1] !== '' ) { if ( $m[1] === 'i' ) { - return $that->indexName( $m[2] ); + return $this->indexName( $m[2] ); } else { - return $that->tableName( $m[2] ); + return $this->tableName( $m[2] ); } } elseif ( isset( $m[3] ) && $m[3] !== '' && array_key_exists( $m[3], $vars ) ) { - return $that->addQuotes( $vars[$m[3]] ); + return $this->addQuotes( $vars[$m[3]] ); } elseif ( isset( $m[4] ) && $m[4] !== '' && array_key_exists( $m[4], $vars ) ) { - return $that->addIdentifierQuotes( $vars[$m[4]] ); + return $this->addIdentifierQuotes( $vars[$m[4]] ); } elseif ( isset( $m[5] ) && $m[5] !== '' && array_key_exists( $m[5], $vars ) ) { return $vars[$m[5]]; } else { @@ -3179,10 +3175,9 @@ abstract class DatabaseBase implements IDatabase { return null; } - $that = $this; - $unlocker = new ScopedCallback( function () use ( $that, $lockKey, $fname ) { - $that->commit( __METHOD__, 'flush' ); - $that->unlock( $lockKey, $fname ); + $unlocker = new ScopedCallback( function () use ( $lockKey, $fname ) { + $this->commit( __METHOD__, 'flush' ); + $this->unlock( $lockKey, $fname ); } ); $this->commit( __METHOD__, 'flush' ); diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 29106abedd..c5aafea6e9 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -692,17 +692,16 @@ abstract class DatabaseMysqlBase extends Database { $this->getLBInfo( 'clusterMasterHost' ) ?: $this->getServer() ); - $that = $this; return $cache->getWithSetCallback( $key, $cache::TTL_INDEFINITE, - function () use ( $that, $cache, $key ) { + function () use ( $cache, $key ) { // Get and leave a lock key in place for a short period if ( !$cache->lock( $key, 0, 10 ) ) { return false; // avoid master connection spike slams } - $conn = $that->getLazyMasterHandle(); + $conn = $this->getLazyMasterHandle(); if ( !$conn ) { return false; // something is misconfigured } diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index 3021af192c..9cd20fc6f7 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -143,9 +143,8 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate { Hooks::run( 'LinksUpdate', array( &$this ) ); $this->doIncrementalUpdate(); - $that = $this; - $this->mDb->onTransactionIdle( function() use ( $that ) { - Hooks::run( 'LinksUpdateComplete', array( &$that ) ); + $this->mDb->onTransactionIdle( function() { + Hooks::run( 'LinksUpdateComplete', array( &$this ) ); } ); } diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index 93d8d07a98..1f64692176 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -278,16 +278,15 @@ class SwiftFileBackend extends FileBackendStore { 'body' => $params['content'] ) ); - $that = $this; $method = __METHOD__; - $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) { + $handler = function ( array $request, Status $status ) use ( $method, $params ) { list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response']; if ( $rcode === 201 ) { // good } elseif ( $rcode === 412 ) { $status->fatal( 'backend-fail-contenttype', $params['dst'] ); } else { - $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); + $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); } }; @@ -343,16 +342,15 @@ class SwiftFileBackend extends FileBackendStore { 'body' => $handle // resource ) ); - $that = $this; $method = __METHOD__; - $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) { + $handler = function ( array $request, Status $status ) use ( $method, $params ) { list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response']; if ( $rcode === 201 ) { // good } elseif ( $rcode === 412 ) { $status->fatal( 'backend-fail-contenttype', $params['dst'] ); } else { - $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); + $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); } }; @@ -392,16 +390,15 @@ class SwiftFileBackend extends FileBackendStore { ) + $this->sanitizeHdrs( $params ), // extra headers merged into object ) ); - $that = $this; $method = __METHOD__; - $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) { + $handler = function ( array $request, Status $status ) use ( $method, $params ) { list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response']; if ( $rcode === 201 ) { // good } elseif ( $rcode === 404 ) { $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); } else { - $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); + $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); } }; @@ -450,9 +447,8 @@ class SwiftFileBackend extends FileBackendStore { ); } - $that = $this; $method = __METHOD__; - $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) { + $handler = function ( array $request, Status $status ) use ( $method, $params ) { list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response']; if ( $request['method'] === 'PUT' && $rcode === 201 ) { // good @@ -461,7 +457,7 @@ class SwiftFileBackend extends FileBackendStore { } elseif ( $rcode === 404 ) { $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] ); } else { - $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); + $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); } }; @@ -491,9 +487,8 @@ class SwiftFileBackend extends FileBackendStore { 'headers' => array() ) ); - $that = $this; $method = __METHOD__; - $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) { + $handler = function ( array $request, Status $status ) use ( $method, $params ) { list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response']; if ( $rcode === 204 ) { // good @@ -502,7 +497,7 @@ class SwiftFileBackend extends FileBackendStore { $status->fatal( 'backend-fail-delete', $params['src'] ); } } else { - $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); + $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); } }; @@ -550,16 +545,15 @@ class SwiftFileBackend extends FileBackendStore { 'headers' => $metaHdrs + $customHdrs ) ); - $that = $this; $method = __METHOD__; - $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) { + $handler = function ( array $request, Status $status ) use ( $method, $params ) { list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response']; if ( $rcode === 202 ) { // good } elseif ( $rcode === 404 ) { $status->fatal( 'backend-fail-describe', $params['src'] ); } else { - $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); + $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc ); } }; diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php index f10866e55a..51dec65d1b 100644 --- a/includes/jobqueue/JobQueueDB.php +++ b/includes/jobqueue/JobQueueDB.php @@ -181,11 +181,10 @@ class JobQueueDB extends JobQueue { protected function doBatchPush( array $jobs, $flags ) { $dbw = $this->getMasterDB(); - $that = $this; $method = __METHOD__; $dbw->onTransactionIdle( - function () use ( $dbw, $that, $jobs, $flags, $method ) { - $that->doBatchPushInternal( $dbw, $jobs, $flags, $method ); + function () use ( $dbw, $jobs, $flags, $method ) { + $this->doBatchPushInternal( $dbw, $jobs, $flags, $method ); } ); } diff --git a/includes/jobqueue/JobQueueMemory.php b/includes/jobqueue/JobQueueMemory.php index 7dad748798..7e9c0c971f 100644 --- a/includes/jobqueue/JobQueueMemory.php +++ b/includes/jobqueue/JobQueueMemory.php @@ -175,11 +175,10 @@ class JobQueueMemory extends JobQueue { return new ArrayIterator( array() ); } - $that = $this; return new MappedIterator( $unclaimed, - function ( $value ) use ( $that ) { - $that->jobFromSpecInternal( $value ); + function ( $value ) { + $this->jobFromSpecInternal( $value ); } ); } @@ -195,11 +194,10 @@ class JobQueueMemory extends JobQueue { return new ArrayIterator( array() ); } - $that = $this; return new MappedIterator( $claimed, - function ( $value ) use ( $that ) { - $that->jobFromSpecInternal( $value ); + function ( $value ) { + $this->jobFromSpecInternal( $value ); } ); } diff --git a/includes/jobqueue/JobQueueRedis.php b/includes/jobqueue/JobQueueRedis.php index eda3e9ccc3..408828dbc2 100644 --- a/includes/jobqueue/JobQueueRedis.php +++ b/includes/jobqueue/JobQueueRedis.php @@ -573,12 +573,10 @@ LUA; * @return MappedIterator */ protected function getJobIterator( RedisConnRef $conn, array $uids ) { - $that = $this; - return new MappedIterator( $uids, - function ( $uid ) use ( $that, $conn ) { - return $that->getJobFromUidInternal( $uid, $conn ); + function ( $uid ) use ( $conn ) { + return $this->getJobFromUidInternal( $uid, $conn ); }, array( 'accept' => function ( $job ) { return is_object( $job ); diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index 3736103351..a7e8a4780b 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -397,18 +397,15 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { } $lSince = microtime( true ); // lock timestamp - // PHP 5.3: Can't use $this in a closure - $that = $this; - $logger = $this->logger; - return new ScopedCallback( function() use ( $that, $logger, $key, $lSince, $expiry ) { + return new ScopedCallback( function() use ( $key, $lSince, $expiry ) { $latency = .050; // latency skew (err towards keeping lock present) $age = ( microtime( true ) - $lSince + $latency ); if ( ( $age + $latency ) >= $expiry ) { - $logger->warning( "Lock for $key held too long ($age sec)." ); + $this->logger->warning( "Lock for $key held too long ($age sec)." ); return; // expired; it's not "safe" to delete the key } - $that->unlock( $key ); + $this->unlock( $key ); } ); } diff --git a/includes/session/SessionBackend.php b/includes/session/SessionBackend.php index a79c5cb089..fe446e356b 100644 --- a/includes/session/SessionBackend.php +++ b/includes/session/SessionBackend.php @@ -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() && diff --git a/includes/session/SessionInfo.php b/includes/session/SessionInfo.php index 9fe2cdf15c..ff40aa5a5d 100644 --- a/includes/session/SessionInfo.php +++ b/includes/session/SessionInfo.php @@ -23,10 +23,6 @@ namespace MediaWiki\Session; -use Psr\Log\LoggerInterface; -use BagOStuff; -use WebRequest; - /** * Value object returned by SessionProvider * diff --git a/includes/session/SessionManager.php b/includes/session/SessionManager.php index 07291e98e8..83c30aba3b 100644 --- a/includes/session/SessionManager.php +++ b/includes/session/SessionManager.php @@ -28,8 +28,6 @@ use BagOStuff; use CachedBagOStuff; use Config; use FauxRequest; -use Language; -use Message; use User; use WebRequest; diff --git a/includes/user/BotPassword.php b/includes/user/BotPassword.php index 6f713f1b29..fca777591e 100644 --- a/includes/user/BotPassword.php +++ b/includes/user/BotPassword.php @@ -18,9 +18,6 @@ * http://www.gnu.org/copyleft/gpl.html */ -use MediaWiki\Session\BotPasswordSessionProvider; -use MediaWiki\Session\SessionInfo; - /** * Utility class for bot passwords * @since 1.27 diff --git a/includes/user/User.php b/includes/user/User.php index 6638fb7ded..da6307551c 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -1789,14 +1789,14 @@ class User implements IDBAccessObject { // ip-based limits if ( isset( $limits['ip'] ) ) { $ip = $this->getRequest()->getIP(); - $keys[wfMemcKey( 'limiter', $action, 'ip', $ip )] = $limits['ip']; + $keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip']; } // subnet-based limits if ( isset( $limits['subnet'] ) ) { $ip = $this->getRequest()->getIP(); $subnet = IP::getSubnet( $ip ); if ( $subnet !== false ) { - $keys[wfMemcKey( 'limiter', $action, 'subnet', $subnet )] = $limits['subnet']; + $keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet']; } } } diff --git a/includes/utils/AutoloadGenerator.php b/includes/utils/AutoloadGenerator.php index 7d6315631e..69426d7126 100644 --- a/includes/utils/AutoloadGenerator.php +++ b/includes/utils/AutoloadGenerator.php @@ -310,6 +310,7 @@ class ClassCollector { case T_NAMESPACE: case T_CLASS: case T_INTERFACE: + case T_TRAIT: $this->startToken = $token; } } @@ -331,6 +332,7 @@ class ClassCollector { case T_CLASS: case T_INTERFACE: + case T_TRAIT: $this->tokens[] = $token; if ( is_array( $token ) && $token[0] === T_STRING ) { $this->classes[] = $this->namespace . $this->implodeTokens(); diff --git a/tests/phpunit/includes/api/ApiMessageTest.php b/tests/phpunit/includes/api/ApiMessageTest.php index 08a984eb25..56bbd064c5 100644 --- a/tests/phpunit/includes/api/ApiMessageTest.php +++ b/tests/phpunit/includes/api/ApiMessageTest.php @@ -25,6 +25,7 @@ class ApiMessageTest extends MediaWikiTestCase { /** * @covers ApiMessage + * @covers ApiMessageTrait */ public function testApiMessage() { $msg = new Message( array( 'foo', 'bar' ), array( 'baz' ) ); @@ -63,6 +64,7 @@ class ApiMessageTest extends MediaWikiTestCase { /** * @covers ApiRawMessage + * @covers ApiMessageTrait */ public function testApiRawMessage() { $msg = new RawMessage( 'foo', array( 'baz' ) ); diff --git a/tests/phpunit/includes/session/CookieSessionProviderTest.php b/tests/phpunit/includes/session/CookieSessionProviderTest.php index f5c8b05b78..659826fb53 100644 --- a/tests/phpunit/includes/session/CookieSessionProviderTest.php +++ b/tests/phpunit/includes/session/CookieSessionProviderTest.php @@ -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(), diff --git a/tests/phpunit/includes/session/SessionInfoTest.php b/tests/phpunit/includes/session/SessionInfoTest.php index b411f3c48d..f9c9b8ee67 100644 --- a/tests/phpunit/includes/session/SessionInfoTest.php +++ b/tests/phpunit/includes/session/SessionInfoTest.php @@ -2,7 +2,6 @@ namespace MediaWiki\Session; -use Psr\Log\LogLevel; use MediaWikiTestCase; /** diff --git a/tests/phpunit/includes/session/SessionManagerTest.php b/tests/phpunit/includes/session/SessionManagerTest.php index 6be8957709..16beb7299e 100644 --- a/tests/phpunit/includes/session/SessionManagerTest.php +++ b/tests/phpunit/includes/session/SessionManagerTest.php @@ -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; } )