Unsuppress other phan issues (part 4)
authorDaimona Eaytoy <daimona.wiki@gmail.com>
Fri, 30 Aug 2019 16:01:28 +0000 (18:01 +0200)
committerDaimona Eaytoy <daimona.wiki@gmail.com>
Sat, 31 Aug 2019 17:13:39 +0000 (17:13 +0000)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84

38 files changed:
.phan/config.php
includes/GlobalFunctions.php
includes/OutputPage.php
includes/Permissions/PermissionManager.php
includes/Title.php
includes/api/ApiBase.php
includes/api/ApiEditPage.php
includes/api/ApiOpenSearch.php
includes/api/ApiQueryUsers.php
includes/auth/AuthenticationRequest.php
includes/cache/CacheHelper.php
includes/cache/MessageCache.php
includes/cache/localisation/LCStoreCDB.php
includes/changes/RecentChange.php
includes/diff/DiffOp.php
includes/filerepo/file/ForeignAPIFile.php
includes/gallery/ImageGalleryBase.php
includes/htmlform/fields/HTMLAutoCompleteSelectField.php
includes/http/GuzzleHttpRequest.php
includes/libs/filebackend/SwiftFileBackend.php
includes/libs/rdbms/database/position/MySQLMasterPos.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php
includes/media/FormatMetadata.php
includes/objectcache/SqlBagOStuff.php
includes/page/WikiPage.php
includes/resourceloader/DerivativeResourceLoaderContext.php
includes/resourceloader/ResourceLoaderContext.php
includes/specials/pagers/BlockListPager.php
includes/user/User.php
includes/utils/ClassCollector.php
includes/widget/search/SearchFormWidget.php
languages/Language.php
languages/LanguageConverter.php
maintenance/copyFileBackend.php
maintenance/generateSitemap.php
maintenance/importDump.php
maintenance/includes/TextPassDumper.php
maintenance/storage/recompressTracked.php

index bc9526a..29729ae 100644 (file)
@@ -84,14 +84,10 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [
        "PhanParamTooMany",
        // approximate error count: 63
        "PhanTypeArraySuspicious",
-       // approximate error count: 28
-       "PhanTypeArraySuspiciousNullable",
        // approximate error count: 88
        "PhanTypeInvalidDimOffset",
        // approximate error count: 60
        "PhanTypeMismatchArgument",
-       // approximate error count: 40
-       "PhanTypeMismatchProperty",
        // approximate error count: 36
        "PhanUndeclaredConstant",
        // approximate error count: 219
index 9e7dd8f..4ae9237 100644 (file)
@@ -1127,6 +1127,7 @@ function wfLogProfilingData() {
        if ( isset( $ctx['forwarded_for'] ) ||
                isset( $ctx['client_ip'] ) ||
                isset( $ctx['from'] ) ) {
+               // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
                $ctx['proxy'] = $_SERVER['REMOTE_ADDR'];
        }
 
index 327bc8f..1703565 100644 (file)
@@ -44,7 +44,7 @@ use Wikimedia\WrappedStringList;
  * @todo document
  */
 class OutputPage extends ContextSource {
-       /** @var array Should be private. Used with addMeta() which adds "<meta>" */
+       /** @var string[][] Should be private. Used with addMeta() which adds "<meta>" */
        protected $mMetatags = [];
 
        /** @var array */
index 6c614f6..0a8e515 100644 (file)
@@ -85,8 +85,8 @@ class PermissionManager {
        /** @var NamespaceInfo */
        private $nsInfo;
 
-       /** @var string[] Cached results of getAllRights() */
-       private $allRights = false;
+       /** @var string[]|null Cached results of getAllRights() */
+       private $allRights;
 
        /** @var string[][] Cached user rights */
        private $usersRights = null;
@@ -1471,7 +1471,7 @@ class PermissionManager {
         * @return string[] Array of permission names
         */
        public function getAllPermissions() {
-               if ( $this->allRights === false ) {
+               if ( $this->allRights === null ) {
                        if ( count( $this->options->get( 'AvailableRights' ) ) ) {
                                $this->allRights = array_unique( array_merge(
                                        $this->coreRights,
index 8c5bbdc..3bf87c2 100644 (file)
@@ -178,8 +178,8 @@ class Title implements LinkTarget, IDBAccessObject {
        /** @var bool Whether a page has any subpages */
        private $mHasSubpages;
 
-       /** @var bool The (string) language code of the page's language and content code. */
-       private $mPageLanguage = false;
+       /** @var array|null The (string) language code of the page's language and content code. */
+       private $mPageLanguage;
 
        /** @var string|bool|null The page language code from the database, null if not saved in
         * the database or false if not loaded, yet.
@@ -3163,7 +3163,7 @@ class Title implements LinkTarget, IDBAccessObject {
                $this->mLatestID = false;
                $this->mContentModel = false;
                $this->mEstimateRevisions = null;
-               $this->mPageLanguage = false;
+               $this->mPageLanguage = null;
                $this->mDbPageLanguage = false;
                $this->mIsBigDeletion = null;
        }
index 8b6a3e5..d8134bb 100644 (file)
@@ -274,7 +274,7 @@ abstract class ApiBase extends ContextSource {
        /** @var array Maps extension paths to info arrays */
        private static $extensionInfo = null;
 
-       /** @var int[][][] Cache for self::filterIDs() */
+       /** @var stdClass[][] Cache for self::filterIDs() */
        private static $filterIDsCache = [];
 
        /** $var array Map of web UI block messages to corresponding API messages and codes */
index 3f63a00..e631e3f 100644 (file)
@@ -62,9 +62,7 @@ class ApiEditPage extends ApiBase {
 
                                /** @var Title $newTitle */
                                foreach ( $titles as $id => $newTitle ) {
-                                       if ( !isset( $titles[$id - 1] ) ) {
-                                               $titles[$id - 1] = $oldTitle;
-                                       }
+                                       $titles[ $id - 1 ] = $titles[ $id - 1 ] ?? $oldTitle;
 
                                        $redirValues[] = [
                                                'from' => $titles[$id - 1]->getPrefixedText(),
index 8e2837b..6a575ec 100644 (file)
@@ -111,6 +111,8 @@ class ApiOpenSearch extends ApiBase {
         * @param string $search the search query
         * @param array $params api request params
         * @return array search results. Keys are integers.
+        * @phan-return array<array{title:Title,extract:false,image:false,url:string}>
+        *  Note that phan annotations don't support keys containing a space.
         */
        private function search( $search, array $params ) {
                $searchEngine = $this->buildSearchEngine( $params );
@@ -247,6 +249,7 @@ class ApiOpenSearch extends ApiBase {
                                        if ( is_string( $r['extract'] ) && $r['extract'] !== '' ) {
                                                $item['Description'] = $r['extract'];
                                        }
+                                       // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
                                        if ( is_array( $r['image'] ) && isset( $r['image']['source'] ) ) {
                                                $item['Image'] = array_intersect_key( $r['image'], $imageKeys );
                                        }
index 8e26d37..ce51a67 100644 (file)
@@ -332,8 +332,8 @@ class ApiQueryUsers extends ApiQueryBase {
                                }
                        }
 
-                       $fit = $result->addValue( [ 'query', $this->getModuleName() ],
-                               null, $data[$u] );
+                       // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
+                       $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $data[$u] );
                        if ( !$fit ) {
                                if ( $useNames ) {
                                        $this->setContinueEnumParameter( 'users',
index 4200341..f59760a 100644 (file)
@@ -337,12 +337,14 @@ abstract class AuthenticationRequest {
                                }
 
                                $options['sensitive'] = !empty( $options['sensitive'] );
+                               // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
+                               $type = $options['type'];
 
                                if ( !array_key_exists( $name, $merged ) ) {
                                        $merged[$name] = $options;
-                               } elseif ( $merged[$name]['type'] !== $options['type'] ) {
+                               } elseif ( $merged[$name]['type'] !== $type ) {
                                        throw new \UnexpectedValueException( "Field type conflict for \"$name\", " .
-                                               "\"{$merged[$name]['type']}\" vs \"{$options['type']}\""
+                                               "\"{$merged[$name]['type']}\" vs \"$type\""
                                        );
                                } else {
                                        if ( isset( $options['options'] ) ) {
index d798ddb..d1261a8 100644 (file)
@@ -82,9 +82,9 @@ class CacheHelper implements ICacheHelper {
         * Function that gets called when initialization is done.
         *
         * @since 1.20
-        * @var callable
+        * @var callable|null
         */
-       protected $onInitHandler = false;
+       protected $onInitHandler;
 
        /**
         * Elements to build a cache key with.
@@ -183,7 +183,7 @@ class CacheHelper implements ICacheHelper {
                        $this->hasCached = is_array( $cachedChunks );
                        $this->cachedChunks = $this->hasCached ? $cachedChunks : [];
 
-                       if ( $this->onInitHandler !== false ) {
+                       if ( $this->onInitHandler !== null ) {
                                call_user_func( $this->onInitHandler, $this->hasCached );
                        }
                }
index 3a6d892..848d9c9 100644 (file)
@@ -1191,6 +1191,7 @@ class MessageCache {
                        $class = $wgParserConf['class'];
                        if ( $class == ParserDiffTest::class ) {
                                # Uncloneable
+                               // @phan-suppress-next-line PhanTypeMismatchProperty
                                $this->mParser = new $class( $wgParserConf );
                        } else {
                                $this->mParser = clone $parser;
index aad9439..fd9af39 100644 (file)
@@ -33,7 +33,7 @@ use Cdb\Writer;
  */
 class LCStoreCDB implements LCStore {
 
-       /** @var Reader[] */
+       /** @var Reader[]|false[] */
        private $readers;
 
        /** @var Writer */
index 0c6a3d1..edaa963 100644 (file)
@@ -94,12 +94,12 @@ class RecentChange implements Taggable {
        public $mExtra = [];
 
        /**
-        * @var Title
+        * @var Title|false
         */
        public $mTitle = false;
 
        /**
-        * @var User
+        * @var User|false
         */
        private $mPerformer = false;
 
index 2a1f3e1..df2792f 100644 (file)
@@ -42,12 +42,12 @@ abstract class DiffOp {
        public $type;
 
        /**
-        * @var string[]
+        * @var string[]|false
         */
        public $orig;
 
        /**
-        * @var string[]
+        * @var string[]|false
         */
        public $closing;
 
index ab8ef2f..99ead16 100644 (file)
@@ -75,6 +75,7 @@ class ForeignAPIFile extends File {
                                ? count( $data['query']['redirects'] ) - 1
                                : -1;
                        if ( $lastRedirect >= 0 ) {
+                               // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
                                $newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to'] );
                                $img = new self( $newtitle, $repo, $info, true );
                                $img->redirectedFrom( $title->getDBkey() );
index 991ef79..c6d8ddf 100644 (file)
@@ -75,7 +75,7 @@ abstract class ImageGalleryBase extends ContextSource {
        protected $mHideBadImages;
 
        /**
-        * @var Parser Registered parser object for output callbacks
+        * @var Parser|false Registered parser object for output callbacks
         */
        public $mParser;
 
@@ -88,8 +88,8 @@ abstract class ImageGalleryBase extends ContextSource {
        /** @var array */
        protected $mAttribs = [];
 
-       /** @var bool */
-       private static $modeMapping = false;
+       /** @var array */
+       private static $modeMapping;
 
        /**
         * Get a new image gallery. This is the method other callers
@@ -121,7 +121,7 @@ abstract class ImageGalleryBase extends ContextSource {
        }
 
        private static function loadModes() {
-               if ( self::$modeMapping === false ) {
+               if ( self::$modeMapping === null ) {
                        self::$modeMapping = [
                                'traditional' => TraditionalImageGallery::class,
                                'nolines' => NolinesImageGallery::class,
index 4ae52a9..41c0b3c 100644 (file)
@@ -29,6 +29,8 @@
  * The old name of autocomplete-data[-messages] was autocomplete[-messages] which is still
  * recognized but deprecated since MediaWiki 1.29 since it conflicts with how autocomplete is
  * used in HTMLTextField.
+ *
+ * @phan-file-suppress PhanTypeMismatchProperty This is doing weird things with mClass
  */
 class HTMLAutoCompleteSelectField extends HTMLTextField {
        protected $autocompleteData = [];
index 3af7f56..fa6dad7 100644 (file)
@@ -41,6 +41,7 @@ class GuzzleHttpRequest extends MWHttpRequest {
 
        protected $handler = null;
        protected $sink = null;
+       /** @var array */
        protected $guzzleOptions = [ 'http_errors' => false ];
 
        /**
index 1e9c7c5..6d6451e 100644 (file)
@@ -1049,6 +1049,7 @@ class SwiftFileBackend extends FileBackendStore {
                                $stat = $this->getFileStat( $params );
                        }
 
+                       // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
                        return $stat['xattr'];
                } else {
                        return false;
index 54eca79..fa2c1db 100644 (file)
@@ -17,7 +17,7 @@ use UnexpectedValueException;
  * @see https://dev.mysql.com/doc/refman/5.6/en/replication-gtids-concepts.html
  */
 class MySQLMasterPos implements DBMasterPos {
-       /** @var int One of (BINARY_LOG, GTID_MYSQL, GTID_MARIA) */
+       /** @var string One of (BINARY_LOG, GTID_MYSQL, GTID_MARIA) */
        private $style;
        /** @var string|null Base name of all Binary Log files */
        private $binLog;
index 585a782..771700c 100644 (file)
@@ -68,7 +68,9 @@ class LoadBalancer implements ILoadBalancer {
        /** @var DatabaseDomain Local DB domain ID and default for selectDB() calls */
        private $localDomain;
 
-       /** @var Database[][][] Map of (connection category => server index => IDatabase[]) */
+       /**
+        * @var IDatabase[][][]|Database[][][] Map of (connection category => server index => IDatabase[])
+        */
        private $conns;
 
        /** @var array[] Map of (server index => server config array) */
@@ -99,7 +101,7 @@ class LoadBalancer implements ILoadBalancer {
        private $tableAliases = [];
        /** @var string[] Map of (index alias => index) */
        private $indexAliases = [];
-       /** @var array[] Map of (name => callable) */
+       /** @var callable[] Map of (name => callable) */
        private $trxRecurringCallbacks = [];
        /** @var bool[] Map of (domain => whether to use "temp tables only" mode) */
        private $tempTablesOnlyMode = [];
index f328760..3993795 100644 (file)
@@ -98,6 +98,7 @@ class FormatMetadata extends ContextSource {
         *   Exif::getFilteredData() or BitmapMetadataHandler )
         * @return array
         * @since 1.23
+        * @suppress PhanTypeArraySuspiciousNullable
         */
        public function makeFormattedData( $tags ) {
                $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
index e634edc..d713396 100644 (file)
@@ -144,7 +144,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff {
                        $this->numServerShards = count( $this->serverInfos );
                } else {
                        // Default to using the main wiki's database servers
-                       $this->serverInfos = false;
+                       $this->serverInfos = [];
                        $this->numServerShards = 1;
                        $this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_BE;
                }
index 4607535..b4b5927 100644 (file)
@@ -68,7 +68,9 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public $mLatest = false;
 
-       /** @var PreparedEdit Map of cache fields (text, parser output, ect) for a proposed/new edit */
+       /**
+        * @var PreparedEdit|false Map of cache fields (text, parser output, ect) for a proposed/new edit
+        */
        public $mPreparedEdit = false;
 
        /**
index cf0b3c2..d84a92a 100644 (file)
@@ -35,6 +35,7 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
         */
        private $context;
 
+       /** @var int|array */
        protected $modules = self::INHERIT_VALUE;
        protected $language = self::INHERIT_VALUE;
        protected $direction = self::INHERIT_VALUE;
@@ -54,7 +55,7 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext {
                if ( $this->modules === self::INHERIT_VALUE ) {
                        return $this->context->getModules();
                }
-               // @phan-suppress-next-line PhanTypeMismatchReturn
+
                return $this->modules;
        }
 
index eab5de0..95b8ff0 100644 (file)
@@ -55,6 +55,7 @@ class ResourceLoaderContext implements MessageLocalizer {
        protected $direction;
        protected $hash;
        protected $userObj;
+       /** @var ResourceLoaderImage|false */
        protected $imageObj;
 
        /**
index 77b7326..d61a1be 100644 (file)
@@ -70,6 +70,12 @@ class BlockListPager extends TablePager {
                return $headers;
        }
 
+       /**
+        * @param string $name
+        * @param string $value
+        * @return string
+        * @suppress PhanTypeArraySuspiciousNullable
+        */
        function formatValue( $name, $value ) {
                static $msg = null;
                if ( $msg === null ) {
index 23c4cfb..82f2ddc 100644 (file)
@@ -110,12 +110,6 @@ class User implements IDBAccessObject, UserIdentity {
                'mActorId',
        ];
 
-       /**
-        * @var string[]
-        * @var string[] Cached results of getAllRights()
-        */
-       protected static $mAllRights = false;
-
        /** Cache variables */
        // @{
        /** @var int */
index a9f7dd2..cf62f6d 100644 (file)
@@ -39,7 +39,7 @@ class ClassCollector {
        protected $startToken;
 
        /**
-        * @var array List of tokens that are members of the current expect sequence
+        * @var array[]|string[] List of tokens that are members of the current expect sequence
         */
        protected $tokens;
 
index 62ee9cb..fedac4b 100644 (file)
@@ -148,6 +148,7 @@ class SearchFormWidget {
         * @param string $profile The currently selected profile
         * @param string $term The user provided search terms
         * @return string HTML
+        * @suppress PhanTypeArraySuspiciousNullable
         */
        protected function profileTabsHtml( $profile, $term ) {
                $bareterm = $this->startsWithImage( $term )
index 9136203..7ee6a65 100644 (file)
@@ -61,7 +61,9 @@ class Language {
 
        public $mVariants, $mCode, $mLoaded = false;
        public $mMagicExtensions = [];
-       private $mHtmlCode = null, $mParentLanguage = false;
+       private $mHtmlCode = null;
+       /** @var Language|false */
+       private $mParentLanguage = false;
 
        public $dateFormatStrings = [];
        public $mExtendedSpecialPageAliases;
@@ -455,6 +457,7 @@ class Language {
        }
 
        function __construct() {
+               // @phan-suppress-next-line PhanTypeMismatchProperty
                $this->mConverter = new FakeConverter( $this );
                // Set the code to the name of the descendant
                if ( static::class === 'Language' ) {
@@ -3235,6 +3238,7 @@ class Language {
                $fallbackChain = array_reverse( $fallbackChain );
                foreach ( $fallbackChain as $code ) {
                        if ( isset( $newWords[$code] ) ) {
+                               // @phan-suppress-next-line PhanTypeMismatchProperty
                                $this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions;
                        }
                }
index d1a5720..350aa67 100644 (file)
@@ -63,8 +63,7 @@ class LanguageConverter {
        public $mTablesLoaded = false;
 
        /**
-        * @var ReplacementArray[]
-        * @phan-var array<string,ReplacementArray>
+        * @var ReplacementArray[]|bool[]
         */
        public $mTables;
 
@@ -958,7 +957,7 @@ class LanguageConverter {
                }
 
                $this->mTablesLoaded = true;
-               $this->mTables = false;
+               $this->mTables = null;
                $cache = ObjectCache::getInstance( $wgLanguageConverterCacheType );
                $cacheKey = $cache->makeKey( 'conversiontables', $this->mMainLanguageCode );
                if ( $fromCache ) {
index 1142325..ce40638 100644 (file)
@@ -358,6 +358,7 @@ class CopyFileBackend extends Maintenance {
                        // backends in FileBackendMultiWrite (since they get writes second, they have
                        // higher timestamps). However, when copying the other way, this hits loads of
                        // false positives (possibly 100%) and wastes a bunch of time on GETs/PUTs.
+                       // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
                        $same = ( $srcStat['mtime'] <= $dstStat['mtime'] );
                } else {
                        // This is the slowest method which does many per-file HEADs (unless an object
index aef45bf..4c3fe7b 100644 (file)
@@ -132,7 +132,7 @@ class GenerateSitemap extends Maintenance {
        /**
         * A resource pointing to a sitemap file
         *
-        * @var resource
+        * @var resource|false
         */
        public $file;
 
index c2c5ccf..0ff3622 100644 (file)
@@ -41,6 +41,7 @@ class BackupReader extends Maintenance {
        public $uploads = false;
        protected $uploadCount = 0;
        public $imageBasePath = false;
+       /** @var array|false */
        public $nsFilter = false;
 
        function __construct() {
index 2e5cc4f..bcf84aa 100644 (file)
@@ -74,14 +74,14 @@ class TextPassDumper extends BackupDumper {
        protected $spawnProc = false;
 
        /**
-        * @var bool|resource
+        * @var resource
         */
-       protected $spawnWrite = false;
+       protected $spawnWrite;
 
        /**
-        * @var bool|resource
+        * @var resource
         */
-       protected $spawnRead = false;
+       protected $spawnRead;
 
        /**
         * @var bool|resource
@@ -809,11 +809,11 @@ TEXT
                if ( $this->spawnRead ) {
                        fclose( $this->spawnRead );
                }
-               $this->spawnRead = false;
+               $this->spawnRead = null;
                if ( $this->spawnWrite ) {
                        fclose( $this->spawnWrite );
                }
-               $this->spawnWrite = false;
+               $this->spawnWrite = null;
                if ( $this->spawnErr ) {
                        fclose( $this->spawnErr );
                }
index 92b6679..316d2d2 100644 (file)
@@ -710,7 +710,7 @@ class CgzCopyTransaction {
        /** @var RecompressTracked */
        public $parent;
        public $blobClass;
-       /** @var ConcatenatedGzipHistoryBlob */
+       /** @var ConcatenatedGzipHistoryBlob|false */
        public $cgz;
        public $referrers;