From 90538900208d227c360613cda8c7904ce2e9dacb Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Tue, 6 Dec 2016 16:06:39 -0800 Subject: [PATCH] Cleanup static analysis errors While prepping the code base for using etsy/phan i found a few problems. A couple are real problems, while others are just places etsy couldn't figure out the types. * AuthPlugin referenced UserLoginTemplate which doesn't exist. Tracing back usages this accepts classes that extend from BaseTemplate. * DatabaseSqlite had an invalid @var annotation. * LoadBalancer had some missing or under-defined annotations. Make them more specific where possible. * SqlBagOStuff didn't have the appropriate use statement for WaitConditionLoop and probably doesn't work. Also updated annotations that point to non-existent DatabaseBase to use IDatabase. Change-Id: Iff2270b418ad2f8f97cfdb6df646c435d3283536 --- includes/AuthPlugin.php | 2 +- includes/libs/rdbms/database/DatabaseSqlite.php | 2 +- includes/libs/rdbms/loadbalancer/LoadBalancer.php | 14 +++++++++++++- includes/objectcache/SqlBagOStuff.php | 1 + maintenance/backup.inc | 6 +++--- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/includes/AuthPlugin.php b/includes/AuthPlugin.php index 0b65593faf..b85e1d6fc1 100644 --- a/includes/AuthPlugin.php +++ b/includes/AuthPlugin.php @@ -73,7 +73,7 @@ class AuthPlugin { /** * Modify options in the login template. * - * @param UserLoginTemplate $template + * @param BaseTemplate $template * @param string $type 'signup' or 'login'. Added in 1.16. */ public function modifyUITemplate( &$template, &$type ) { diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php b/includes/libs/rdbms/database/DatabaseSqlite.php index 7317d54070..a06aad2cfd 100644 --- a/includes/libs/rdbms/database/DatabaseSqlite.php +++ b/includes/libs/rdbms/database/DatabaseSqlite.php @@ -41,7 +41,7 @@ class DatabaseSqlite extends Database { /** @var resource */ protected $mLastResult; - /** @var $mConn PDO */ + /** @var PDO */ protected $mConn; /** @var FSLockManager (hopefully on the same server as the DB) */ diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index d42fed9590..634993ac2e 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -31,7 +31,7 @@ use Wikimedia\ScopedCallback; class LoadBalancer implements ILoadBalancer { /** @var array[] Map of (server index => server config array) */ private $mServers; - /** @var array[] Map of (local/foreignUsed/foreignFree => server index => IDatabase array) */ + /** @var IDatabase[][] Map of (local/foreignUsed/foreignFree => server index => IDatabase array) */ private $mConns; /** @var float[] Map of (server index => weight) */ private $mLoads; @@ -390,6 +390,9 @@ class LoadBalancer implements ILoadBalancer { return $i; } + /** + * @param DBMasterPos|false $pos + */ public function waitFor( $pos ) { $this->mWaitForPos = $pos; $i = $this->mReadIndex; @@ -436,6 +439,10 @@ class LoadBalancer implements ILoadBalancer { return $ok; } + /** + * @param int $i + * @return IDatabase + */ public function getAnyOpenConnection( $i ) { foreach ( $this->mConns as $connsByServer ) { if ( !empty( $connsByServer[$i] ) ) { @@ -1447,6 +1454,11 @@ class LoadBalancer implements ILoadBalancer { } } + /** + * @param IDatabase $conn + * @param DBMasterPos|false $pos + * @param int $timeout + */ public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 ) { if ( $this->getServerCount() <= 1 || !$conn->getLBInfo( 'replica' ) ) { return true; // server is not a replica DB diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 47dae78850..de49fc3458 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -22,6 +22,7 @@ */ use \MediaWiki\MediaWikiServices; +use \Wikimedia\WaitConditionLoop; /** * Class to store objects in the database diff --git a/maintenance/backup.inc b/maintenance/backup.inc index 38daf646fd..18c7f11fbf 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -60,7 +60,7 @@ class BackupDumper extends Maintenance { /** * The dependency-injected database to use. * - * @var DatabaseBase|null + * @var IDatabase|null * * @see self::setDB */ @@ -314,7 +314,7 @@ class BackupDumper extends Maintenance { * @todo Fixme: the --server parameter is currently not respected, as it * doesn't seem terribly easy to ask the load balancer for a particular * connection by name. - * @return DatabaseBase + * @return IDatabase */ function backupDb() { if ( $this->forcedDb !== null ) { @@ -335,7 +335,7 @@ class BackupDumper extends Maintenance { * Force the dump to use the provided database connection for database * operations, wherever possible. * - * @param DatabaseBase|null $db (Optional) the database connection to use. If null, resort to + * @param IDatabase|null $db (Optional) the database connection to use. If null, resort to * use the globally provided ways to get database connections. */ function setDB( IDatabase $db = null ) { -- 2.20.1