Cleanup static analysis errors
authorErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 7 Dec 2016 00:06:39 +0000 (16:06 -0800)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 7 Dec 2016 00:10:38 +0000 (16:10 -0800)
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
includes/libs/rdbms/database/DatabaseSqlite.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php
includes/objectcache/SqlBagOStuff.php
maintenance/backup.inc

index 0b65593..b85e1d6 100644 (file)
@@ -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 ) {
index 7317d54..a06aad2 100644 (file)
@@ -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) */
index d42fed9..634993a 100644 (file)
@@ -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
index 47dae78..de49fc3 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 use \MediaWiki\MediaWikiServices;
+use \Wikimedia\WaitConditionLoop;
 
 /**
  * Class to store objects in the database
index 38daf64..18c7f11 100644 (file)
@@ -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 ) {