From b5cbb5ab3f084da72b12fbca770a3694d03931e9 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 1 Sep 2019 16:00:35 +0200 Subject: [PATCH] Upgrade phan config to 0.7.1 This allows us to remove many suppressions for phan false positives. Bug: T231636 Depends-On: I82a279e1f7b0fdefd3bb712e46c7d0665429d065 Change-Id: I5c251e9584a1ae9fb1577afcafb5001e0dcd41c7 --- .phan/config.php | 15 +++++++++++++-- composer.json | 2 +- includes/GlobalFunctions.php | 3 --- includes/Revision/RevisionRenderer.php | 2 -- includes/actions/HistoryAction.php | 1 + includes/api/ApiExpandTemplates.php | 1 + includes/api/ApiMain.php | 6 +++++- includes/api/ApiQueryBacklinks.php | 1 - includes/api/ApiQueryRevisionsBase.php | 1 + includes/auth/AuthenticationRequest.php | 2 +- .../block/Restriction/AbstractRestriction.php | 2 +- includes/changes/ChangesList.php | 1 + includes/config/EtcdConfig.php | 1 + includes/content/ContentHandler.php | 2 +- includes/diff/DiffEngine.php | 1 - includes/export/ExportProgressFilter.php | 4 ++++ includes/filerepo/RepoGroup.php | 1 - includes/filerepo/file/LocalFile.php | 1 - .../fields/HTMLAutoCompleteSelectField.php | 4 ---- includes/http/MWHttpRequest.php | 1 - includes/libs/MappedIterator.php | 1 - .../fileiteration/SwiftFileBackendList.php | 3 ++- includes/libs/http/MultiHttpClient.php | 1 - includes/libs/objectcache/HashBagOStuff.php | 1 - .../objectcache/wancache/WANObjectCache.php | 5 ++--- .../libs/rdbms/loadmonitor/LoadMonitor.php | 1 + includes/media/ExifBitmapHandler.php | 2 -- includes/parser/Parser.php | 2 -- includes/parser/ParserDiffTest.php | 1 + includes/rcfeed/FormattedRCFeed.php | 1 - .../ResourceLoaderClientHtml.php | 1 - .../ResourceLoaderOOUIImageModule.php | 1 - includes/session/SessionManager.php | 1 - includes/shell/Shell.php | 1 - includes/skins/BaseTemplate.php | 1 - .../SpecialUncategorizedcategories.php | 1 + includes/specials/pagers/BlockListPager.php | 2 +- includes/title/NamespaceInfo.php | 3 ++- includes/user/User.php | 3 ++- languages/Language.php | 3 --- maintenance/Maintenance.php | 18 +++++++++++++++--- maintenance/benchmarks/benchmarkTidy.php | 1 + maintenance/convertExtensionToRegistration.php | 1 - maintenance/importImages.php | 2 +- maintenance/storage/orphanStats.php | 2 +- 45 files changed, 61 insertions(+), 50 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 47f4512246..0ae6fcff56 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -90,6 +90,9 @@ $cfg['exclude_analysis_directory_list'] = [ 'includes/libs/jsminplus.php', ]; +// NOTE: If you're facing an issue which you cannot easily fix, DO NOT add it here. Suppress it +// either in-line with @phan-suppress-next-line and similar, at block-level (via @suppress), or at +// file-level (with @phan-file-suppress), so that it stays enabled for the rest of the codebase. $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ // approximate error count: 19 "PhanParamReqAfterOpt", // False positives with nullables (phan issue #3159). Use real nullables @@ -97,12 +100,17 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ // approximate error count: 110 "PhanParamTooMany", // False positives with variargs. Unsuppress after dropping HHVM - // approximate error count: 60 + // approximate error count: 45 "PhanTypeMismatchArgument", - // approximate error count: 752 + // approximate error count: 693 "PhanUndeclaredProperty", ] ); +// This helps a lot in discovering bad code, but unfortunately it will always fail for +// hooks + pass by reference, see phan issue #2943. +// @todo Enable when the issue above is resolved and we update our config! +$cfg['redundant_condition_detection'] = false; + $cfg['ignore_undeclared_variables_in_global_scope'] = true; // @todo It'd be great if we could just make phan read these from DefaultSettings, to avoid // duplicating the types. @@ -125,6 +133,9 @@ $cfg['globals_type_map'] = array_merge( $cfg['globals_type_map'], [ 'wgWANObjectCaches' => 'array[]', 'wgLocalInterwikis' => 'string[]', 'wgDebugLogGroups' => 'string|false|array{destination:string,sample?:int,level:int}', + 'wgCookiePrefix' => 'string|false', + 'wgOut' => 'OutputPage', + 'wgExtraNamespaces' => 'string[]', ] ); return $cfg; diff --git a/composer.json b/composer.json index dad3c5c83b..13c8993a5f 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,7 @@ "wikimedia/avro": "1.8.0", "wikimedia/testing-access-wrapper": "~1.0", "wmde/hamcrest-html-matchers": "^0.1.0", - "mediawiki/mediawiki-phan-config": "0.6.1", + "mediawiki/mediawiki-phan-config": "0.7.1", "symfony/yaml": "3.4.28", "johnkary/phpunit-speedtrap": "^1.0 | ^2.0" }, diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 2cde173236..38daab5c32 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2135,7 +2135,6 @@ function wfShellExec( $cmd, &$retval = null, $environ = [], } $includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr']; - // @phan-suppress-next-line PhanTypeInvalidDimOffset $profileMethod = $options['profileMethod'] ?? wfGetCaller(); try { @@ -2200,7 +2199,6 @@ function wfShellWikiCmd( $script, array $parameters = [], array $options = [] ) // Give site config file a chance to run the script in a wrapper. // The caller may likely want to call wfBasename() on $script. Hooks::run( 'wfShellWikiCmd', [ &$script, &$parameters, &$options ] ); - // @phan-suppress-next-line PhanTypeInvalidDimOffset $cmd = [ $options['php'] ?? $wgPhpCli ]; if ( isset( $options['wrapper'] ) ) { $cmd[] = $options['wrapper']; @@ -2897,7 +2895,6 @@ function wfUnpack( $format, $data, $length = false ) { $result = unpack( $format, $data ); Wikimedia\restoreWarnings(); - // @phan-suppress-next-line PhanTypeComparisonFromArray Phan issue #3160 if ( $result === false ) { // If it cannot extract the packed data. throw new MWException( "unpack could not unpack binary data" ); diff --git a/includes/Revision/RevisionRenderer.php b/includes/Revision/RevisionRenderer.php index ea9025535a..5d09e011cd 100644 --- a/includes/Revision/RevisionRenderer.php +++ b/includes/Revision/RevisionRenderer.php @@ -109,7 +109,6 @@ class RevisionRenderer { throw new InvalidArgumentException( 'Mismatching wiki ID ' . $rev->getWikiId() ); } - // @phan-suppress-next-line PhanTypeInvalidDimOffset $audience = $hints['audience'] ?? ( $forUser ? RevisionRecord::FOR_THIS_USER : RevisionRecord::FOR_PUBLIC ); @@ -123,7 +122,6 @@ class RevisionRenderer { $options = ParserOptions::newCanonical( $forUser ?: 'canonical' ); } - // @phan-suppress-next-line PhanTypeInvalidDimOffset $useMaster = $hints['use-master'] ?? false; $dbIndex = $useMaster diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 385ccc9607..db874f2de5 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -95,6 +95,7 @@ class HistoryAction extends FormlessAction { private function preCacheMessages() { // Precache various messages if ( !isset( $this->message ) ) { + $this->message = []; $msgs = [ 'cur', 'last', 'pipe-separator' ]; foreach ( $msgs as $msg ) { $this->message[$msg] = $this->msg( $msg )->escaped(); diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index 1c7f63d000..a5e7437108 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -103,6 +103,7 @@ class ApiExpandTemplates extends ApiBase { if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) { $parser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS ); $dom = $parser->preprocessToDom( $params['text'] ); + // @phan-suppress-next-line PhanUndeclaredMethodInCallable if ( is_callable( [ $dom, 'saveXML' ] ) ) { // @phan-suppress-next-line PhanUndeclaredMethod $xml = $dom->saveXML(); diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index efa4b04bbb..a9fe25807b 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1708,7 +1708,7 @@ class ApiMain extends ApiBase { * @return string */ protected function encodeRequestLogValue( $s ) { - static $table; + static $table = []; if ( !$table ) { $chars = ';@$!*(),/:'; $numChars = strlen( $chars ); @@ -1914,6 +1914,10 @@ class ApiMain extends ApiBase { ]; } + /** + * @inheritDoc + * @phan-param array{nolead?:bool,headerlevel?:int,tocnumber?:int[]} $options + */ public function modifyHelp( array &$help, array $options, array &$tocData ) { // Wish PHP had an "array_insert_before". Instead, we have to manually // reindex the array to get 'permissions' in the right place. diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index 6c1eb0f489..d21f1119aa 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -326,7 +326,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { /** * @param ApiPageSet $resultPageSet * @return void - * @suppress PhanTypeInvalidDimOffset */ private function run( $resultPageSet = null ) { $this->params = $this->extractRequestParams( false ); diff --git a/includes/api/ApiQueryRevisionsBase.php b/includes/api/ApiQueryRevisionsBase.php index 7c92b3565a..90e54804e6 100644 --- a/includes/api/ApiQueryRevisionsBase.php +++ b/includes/api/ApiQueryRevisionsBase.php @@ -512,6 +512,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase { Parser::OT_PREPROCESS ); $dom = $parser->preprocessToDom( $t ); + // @phan-suppress-next-line PhanUndeclaredMethodInCallable if ( is_callable( [ $dom, 'saveXML' ] ) ) { // @phan-suppress-next-line PhanUndeclaredMethod $xml = $dom->saveXML(); diff --git a/includes/auth/AuthenticationRequest.php b/includes/auth/AuthenticationRequest.php index 1a2442c9ad..e7527d156f 100644 --- a/includes/auth/AuthenticationRequest.php +++ b/includes/auth/AuthenticationRequest.php @@ -376,7 +376,7 @@ abstract class AuthenticationRequest { * @return AuthenticationRequest */ public static function __set_state( $data ) { - // @phan-suppress-next-line PhanTypeInstantiateAbstract + // @phan-suppress-next-line PhanTypeInstantiateAbstractStatic $ret = new static(); foreach ( $data as $k => $v ) { $ret->$k = $v; diff --git a/includes/block/Restriction/AbstractRestriction.php b/includes/block/Restriction/AbstractRestriction.php index a010e833ab..e08b877aa0 100644 --- a/includes/block/Restriction/AbstractRestriction.php +++ b/includes/block/Restriction/AbstractRestriction.php @@ -99,7 +99,7 @@ abstract class AbstractRestriction implements Restriction { * @inheritDoc */ public static function newFromRow( \stdClass $row ) { - // @phan-suppress-next-line PhanTypeInstantiateAbstract + // @phan-suppress-next-line PhanTypeInstantiateAbstractStatic return new static( $row->ir_ipb_id, $row->ir_value ); } diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index 0382d7360f..a48e191003 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -161,6 +161,7 @@ class ChangesList extends ContextSource { */ private function preCacheMessages() { if ( !isset( $this->message ) ) { + $this->message = []; foreach ( [ 'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history', 'semicolon-separator', 'pipe-separator' ] as $msg diff --git a/includes/config/EtcdConfig.php b/includes/config/EtcdConfig.php index 09d0189a94..f3d3849476 100644 --- a/includes/config/EtcdConfig.php +++ b/includes/config/EtcdConfig.php @@ -161,6 +161,7 @@ class EtcdConfig implements Config, LoggerAwareInterface { if ( is_array( $etcdResponse['config'] ) ) { // Avoid having all servers expire cache keys at the same time $expiry = microtime( true ) + $this->baseCacheTTL; + // @phan-suppress-next-line PhanTypeMismatchArgumentInternal $expiry += mt_rand( 0, 1e6 ) / 1e6 * $this->skewCacheTTL; $data = [ 'config' => $etcdResponse['config'], diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index f1df087354..9fbb72cd1b 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -1102,7 +1102,7 @@ abstract class ContentHandler { * @param Revision|Content $undoafter Must be from an earlier revision than $undo * @param bool $undoIsLatest Set true if $undo is from the current revision (since 1.32) * - * @return mixed Content on success, false on failure + * @return Content|false Content on success, false on failure */ public function getUndoContent( $current, $undo, $undoafter, $undoIsLatest = false ) { Assert::parameterType( Revision::class . '|' . Content::class, $current, '$current' ); diff --git a/includes/diff/DiffEngine.php b/includes/diff/DiffEngine.php index 6ebec1cd18..6fa40ea46c 100644 --- a/includes/diff/DiffEngine.php +++ b/includes/diff/DiffEngine.php @@ -363,7 +363,6 @@ class DiffEngine { */ $max = min( $this->m, $this->n ); for ( $forwardBound = 0; $forwardBound < $max - // @phan-suppress-next-line PhanTypeInvalidDimOffset && $this->from[$forwardBound] === $this->to[$forwardBound]; ++$forwardBound ) { diff --git a/includes/export/ExportProgressFilter.php b/includes/export/ExportProgressFilter.php index 9b1571f7de..5dd3e4c65b 100644 --- a/includes/export/ExportProgressFilter.php +++ b/includes/export/ExportProgressFilter.php @@ -30,6 +30,10 @@ class ExportProgressFilter extends DumpFilter { */ private $progress; + /** + * @param DumpOutput &$sink + * @param BackupDumper &$progress + */ function __construct( &$sink, &$progress ) { parent::__construct( $sink ); $this->progress = $progress; diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 96df29ff51..f61ca3b875 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -116,7 +116,6 @@ class RepoGroup { * be found. * latest: If true, load from the latest available data into File objects * @phan-param array{time?:mixed,ignoreRedirect?:bool,private?:bool,latest?:bool} $options - * @suppress PhanTypeInvalidDimOffset * @return File|bool False if title is not found */ function findFile( $title, $options = [] ) { diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 4751a59031..3090632448 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1092,7 +1092,6 @@ class LocalFile extends File { array_shift( $urls ); // don't purge directory // Give media handler a chance to filter the file purge list - // @phan-suppress-next-line PhanTypeInvalidDimOffset if ( !empty( $options['forThumbRefresh'] ) ) { $handler = $this->getHandler(); if ( $handler ) { diff --git a/includes/htmlform/fields/HTMLAutoCompleteSelectField.php b/includes/htmlform/fields/HTMLAutoCompleteSelectField.php index 41c0b3c72b..63e77cec9d 100644 --- a/includes/htmlform/fields/HTMLAutoCompleteSelectField.php +++ b/includes/htmlform/fields/HTMLAutoCompleteSelectField.php @@ -29,8 +29,6 @@ * 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 = []; @@ -168,7 +166,6 @@ class HTMLAutoCompleteSelectField extends HTMLTextField { $ret = $select->getHTML() . "
\n"; - // @phan-suppress-next-line PhanTypeMismatchDimEmpty $this->mClass[] = 'mw-htmlform-hide-if'; } @@ -181,7 +178,6 @@ class HTMLAutoCompleteSelectField extends HTMLTextField { } } - // @phan-suppress-next-line PhanTypeMismatchDimEmpty $this->mClass[] = 'mw-htmlform-autocomplete'; $ret .= parent::getInputHTML( $valInSelect ? '' : $value ); $this->mClass = $oldClass; diff --git a/includes/http/MWHttpRequest.php b/includes/http/MWHttpRequest.php index 3885c0319a..d1c14aebba 100644 --- a/includes/http/MWHttpRequest.php +++ b/includes/http/MWHttpRequest.php @@ -103,7 +103,6 @@ abstract class MWHttpRequest implements LoggerAwareInterface { $this->url = wfExpandUrl( $url, PROTO_HTTP ); $this->parsedUrl = wfParseUrl( $this->url ); - // @phan-suppress-next-line PhanTypeInvalidDimOffset $this->logger = $options['logger'] ?? new NullLogger(); if ( !$this->parsedUrl || !Http::isValidURI( $this->url ) ) { diff --git a/includes/libs/MappedIterator.php b/includes/libs/MappedIterator.php index 9d53a861f6..0e53038d54 100644 --- a/includes/libs/MappedIterator.php +++ b/includes/libs/MappedIterator.php @@ -61,7 +61,6 @@ class MappedIterator extends FilterIterator { } parent::__construct( $baseIterator ); $this->vCallback = $vCallback; - // @phan-suppress-next-line PhanTypeInvalidDimOffset $this->aCallback = $options['accept'] ?? null; } diff --git a/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php b/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php index bcde8d90a9..92105c350e 100644 --- a/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php +++ b/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php @@ -33,7 +33,7 @@ abstract class SwiftFileBackendList implements Iterator { /** @var array List of path or (path,stat array) entries */ protected $bufferIter = []; - /** @var string List items *after* this path */ + /** @var string|null List items *after* this path */ protected $bufferAfter = null; /** @var int */ @@ -108,6 +108,7 @@ abstract class SwiftFileBackendList implements Iterator { $this->pos = 0; $this->bufferAfter = null; $this->bufferIter = $this->pageFromList( + // @phan-suppress-next-line PhanTypeMismatchArgumentPropertyReferenceReal $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params ); // updates $this->bufferAfter } diff --git a/includes/libs/http/MultiHttpClient.php b/includes/libs/http/MultiHttpClient.php index 17352f03b9..2e3aa70e4e 100644 --- a/includes/libs/http/MultiHttpClient.php +++ b/includes/libs/http/MultiHttpClient.php @@ -402,7 +402,6 @@ class MultiHttpClient implements LoggerAwareInterface { $name = strtolower( $name ); $value = trim( $value ); if ( isset( $req['response']['headers'][$name] ) ) { - // @phan-suppress-next-line PhanTypeInvalidDimOffset $req['response']['headers'][$name] .= ', ' . $value; } else { $req['response']['headers'][$name] = $value; diff --git a/includes/libs/objectcache/HashBagOStuff.php b/includes/libs/objectcache/HashBagOStuff.php index 0f7011d60c..348f300c07 100644 --- a/includes/libs/objectcache/HashBagOStuff.php +++ b/includes/libs/objectcache/HashBagOStuff.php @@ -50,7 +50,6 @@ class HashBagOStuff extends MediumSpecificBagOStuff { * @codingStandardsIgnoreStart * @phan-param array{logger?:Psr\Log\LoggerInterface,asyncHandler?:callable,keyspace?:string,reportDupes?:bool,syncTimeout?:int,segmentationSize?:int,segmentedValueMaxSize?:int,maxKeys?:int} $params * @codingStandardsIgnoreEnd - * @suppress PhanTypeInvalidDimOffset */ function __construct( $params = [] ) { $params['segmentationSize'] = $params['segmentationSize'] ?? INF; diff --git a/includes/libs/objectcache/wancache/WANObjectCache.php b/includes/libs/objectcache/wancache/WANObjectCache.php index 2ce216d08a..a090e16404 100644 --- a/includes/libs/objectcache/wancache/WANObjectCache.php +++ b/includes/libs/objectcache/wancache/WANObjectCache.php @@ -585,7 +585,6 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt * @note Options added in 1.33: creating * @note Options added in 1.34: version, walltime * @return bool Success - * @suppress PhanTypeInvalidDimOffset */ final public function set( $key, $value, $ttl = self::TTL_INDEFINITE, array $opts = [] ) { $now = $this->getCurrentTime(); @@ -1258,7 +1257,6 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt * @note Options added in 1.31: staleTTL, graceTTL * @note Options added in 1.33: touchedCallback * @note Callable type hints are not used to avoid class-autoloading - * @suppress PhanTypeInvalidDimOffset */ final public function getWithSetCallback( $key, $ttl, $callback, array $opts = [] ) { $version = $opts['version'] ?? null; @@ -1450,7 +1448,6 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt $this->setInterimValue( $key, $value, $lockTSE, $version, $walltime ); } else { $finalSetOpts = [ - // @phan-suppress-next-line PhanTypeInvalidDimOffset 'since' => $setOpts['since'] ?? $preCallbackTime, 'version' => $version, 'staleTTL' => $staleTTL, @@ -2328,6 +2325,7 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt $chance = ( 1 - $curTTL / $lowTTL ); + // @phan-suppress-next-line PhanTypeMismatchArgumentInternal return mt_rand( 1, 1e9 ) <= 1e9 * $chance; } @@ -2370,6 +2368,7 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt // Ramp up $chance from 0 to its nominal value over RAMPUP_TTL seconds to avoid stampedes $chance *= ( $timeOld <= self::$RAMPUP_TTL ) ? $timeOld / self::$RAMPUP_TTL : 1; + // @phan-suppress-next-line PhanTypeMismatchArgumentInternal return mt_rand( 1, 1e9 ) <= 1e9 * $chance; } diff --git a/includes/libs/rdbms/loadmonitor/LoadMonitor.php b/includes/libs/rdbms/loadmonitor/LoadMonitor.php index 19550f42a5..c3f8879217 100644 --- a/includes/libs/rdbms/loadmonitor/LoadMonitor.php +++ b/includes/libs/rdbms/loadmonitor/LoadMonitor.php @@ -107,6 +107,7 @@ class LoadMonitor implements ILoadMonitor { $key = $this->getCacheKey( $serverIndexes ); # Randomize TTLs to reduce stampedes (4.0 - 5.0 sec) + // @phan-suppress-next-line PhanTypeMismatchArgumentInternal $ttl = mt_rand( 4e6, 5e6 ) / 1e6; # Keep keys around longer as fallbacks $staleTTL = 60; diff --git a/includes/media/ExifBitmapHandler.php b/includes/media/ExifBitmapHandler.php index 874e87264b..9058340fb6 100644 --- a/includes/media/ExifBitmapHandler.php +++ b/includes/media/ExifBitmapHandler.php @@ -26,8 +26,6 @@ * All metadata related, since both JPEG and TIFF support Exif. * * @ingroup Media - * @phan-file-suppress PhanUndeclaredConstant Phan doesn't read constants in MediaHandler - * when accessed via self:: */ class ExifBitmapHandler extends BitmapHandler { const BROKEN_FILE = '-1'; // error extracting metadata diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 5c55124492..b27338ca2b 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4271,7 +4271,6 @@ class Parser { * @param bool $isMain * @return mixed|string * @private - * @suppress PhanTypeInvalidDimOffset */ public function formatHeadings( $text, $origText, $isMain = true ) { # Inhibit editsection links if requested in the page @@ -5578,7 +5577,6 @@ class Parser { Hooks::run( 'ParserMakeImageParams', [ $title, $file, &$params, $this ] ); # Linker does the rest - // @phan-suppress-next-line PhanTypeInvalidDimOffset $time = $options['time'] ?? false; $ret = Linker::makeImageLink( $this, $title, $file, $params['frame'], $params['handler'], $time, $descQuery, $this->mOptions->getThumbSize() ); diff --git a/includes/parser/ParserDiffTest.php b/includes/parser/ParserDiffTest.php index 93f4246e02..bd610de67f 100644 --- a/includes/parser/ParserDiffTest.php +++ b/includes/parser/ParserDiffTest.php @@ -40,6 +40,7 @@ class ParserDiffTest { if ( !is_null( $this->parsers ) ) { return; } + $this->parsers = []; if ( isset( $this->conf['shortOutput'] ) ) { $this->shortOutput = $this->conf['shortOutput']; diff --git a/includes/rcfeed/FormattedRCFeed.php b/includes/rcfeed/FormattedRCFeed.php index 9b5b29e208..d0b7ae3220 100644 --- a/includes/rcfeed/FormattedRCFeed.php +++ b/includes/rcfeed/FormattedRCFeed.php @@ -61,7 +61,6 @@ abstract class FormattedRCFeed extends RCFeed { // @codeCoverageIgnoreStart // T109544 - If a feed formatter returns null, this will otherwise cause an // error in at least RedisPubSubFeedEngine. Not sure best to handle this. - // @phan-suppress-next-line PhanTypeMismatchReturn return; // @codeCoverageIgnoreEnd } diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php b/includes/resourceloader/ResourceLoaderClientHtml.php index 8303896ef7..151b5fd502 100644 --- a/includes/resourceloader/ResourceLoaderClientHtml.php +++ b/includes/resourceloader/ResourceLoaderClientHtml.php @@ -427,7 +427,6 @@ JAVASCRIPT; $idx = -1; foreach ( $grpModules as $name => $module ) { $shouldEmbed = $module->shouldEmbedModule( $context ); - // @phan-suppress-next-line PhanTypeInvalidDimOffset if ( !$moduleSets || $moduleSets[$idx][0] !== $shouldEmbed ) { $moduleSets[++$idx] = [ $shouldEmbed, [] ]; } diff --git a/includes/resourceloader/ResourceLoaderOOUIImageModule.php b/includes/resourceloader/ResourceLoaderOOUIImageModule.php index 9c204fc711..55e9e53de9 100644 --- a/includes/resourceloader/ResourceLoaderOOUIImageModule.php +++ b/includes/resourceloader/ResourceLoaderOOUIImageModule.php @@ -137,7 +137,6 @@ class ResourceLoaderOOUIImageModule extends ResourceLoaderImageModule { $dataPath->getRemoteBasePath() ); } else { - // @phan-suppress-next-line PhanTypeSuspiciousStringExpression $path = dirname( $dataPath ) . '/' . $path; } }; diff --git a/includes/session/SessionManager.php b/includes/session/SessionManager.php index 1da0cebc93..09cdf72f46 100644 --- a/includes/session/SessionManager.php +++ b/includes/session/SessionManager.php @@ -286,7 +286,6 @@ final class SessionManager implements SessionManagerInterface { "$provider returned empty session info with id flagged unsafe" ); } - // @phan-suppress-next-line PhanTypeInvalidDimOffset $compare = $infos ? SessionInfo::compare( $infos[0], $info ) : -1; if ( $compare > 0 ) { continue; diff --git a/includes/shell/Shell.php b/includes/shell/Shell.php index 74d77a845b..478a615039 100644 --- a/includes/shell/Shell.php +++ b/includes/shell/Shell.php @@ -238,7 +238,6 @@ class Shell { // Give site config file a chance to run the script in a wrapper. // The caller may likely want to call wfBasename() on $script. Hooks::run( 'wfShellWikiCmd', [ &$script, &$parameters, &$options ] ); - // @phan-suppress-next-line PhanTypeInvalidDimOffset $cmd = [ $options['php'] ?? $wgPhpCli ]; if ( isset( $options['wrapper'] ) ) { $cmd[] = $options['wrapper']; diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php index bee4affab6..cd63796088 100644 --- a/includes/skins/BaseTemplate.php +++ b/includes/skins/BaseTemplate.php @@ -516,7 +516,6 @@ abstract class BaseTemplate extends QuickTemplate { if ( isset( $item['itemtitle'] ) ) { $attrs['title'] = $item['itemtitle']; } - // @phan-suppress-next-line PhanTypeInvalidDimOffset return Html::rawElement( $options['tag'] ?? 'li', $attrs, $html ); } diff --git a/includes/specials/SpecialUncategorizedcategories.php b/includes/specials/SpecialUncategorizedcategories.php index 2dcb77f824..60cbff12e3 100644 --- a/includes/specials/SpecialUncategorizedcategories.php +++ b/includes/specials/SpecialUncategorizedcategories.php @@ -47,6 +47,7 @@ class UncategorizedCategoriesPage extends UncategorizedPagesPage { */ private function getExceptionList() { if ( $this->exceptionList === null ) { + $this->exceptionList = []; $exList = $this->msg( 'uncategorized-categories-exceptionlist' ) ->inContentLanguage()->plain(); $proposedTitles = explode( "\n", $exList ); diff --git a/includes/specials/pagers/BlockListPager.php b/includes/specials/pagers/BlockListPager.php index 63cff94593..4441a33314 100644 --- a/includes/specials/pagers/BlockListPager.php +++ b/includes/specials/pagers/BlockListPager.php @@ -74,7 +74,7 @@ class BlockListPager extends TablePager { * @param string $name * @param string $value * @return string - * @suppress PhanTypeArraySuspiciousNullable,PhanTypeArraySuspicious + * @suppress PhanTypeArraySuspicious */ function formatValue( $name, $value ) { static $msg = null; diff --git a/includes/title/NamespaceInfo.php b/includes/title/NamespaceInfo.php index 105eeaa05d..365ec4deb1 100644 --- a/includes/title/NamespaceInfo.php +++ b/includes/title/NamespaceInfo.php @@ -341,7 +341,7 @@ class NamespaceInfo { * Returns array of all defined namespaces with their canonical * (English) names. * - * @return array + * @return string[] */ public function getCanonicalNamespaces() { if ( $this->canonicalNamespaces === null ) { @@ -396,6 +396,7 @@ class NamespaceInfo { */ public function getValidNamespaces() { if ( is_null( $this->validNamespaces ) ) { + $this->validNamespaces = []; foreach ( array_keys( $this->getCanonicalNamespaces() ) as $ns ) { if ( $ns >= 0 ) { $this->validNamespaces[] = $ns; diff --git a/includes/user/User.php b/includes/user/User.php index ad6b5b81d9..706887962c 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -249,7 +249,8 @@ class User implements IDBAccessObject, UserIdentity { return $this->$name; } else { wfLogWarning( 'tried to get non-visible property' ); - return null; + $null = null; + return $null; } } diff --git a/languages/Language.php b/languages/Language.php index 16a6e1a778..51ff8d5b1b 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -527,7 +527,6 @@ class Language { } # Sometimes a language will be localised but not actually exist on this wiki. - // @phan-suppress-next-line PhanTypeMismatchForeach foreach ( $this->namespaceNames as $key => $text ) { if ( !isset( $validNamespaces[$key] ) ) { unset( $this->namespaceNames[$key] ); @@ -536,7 +535,6 @@ class Language { # The above mixing may leave namespaces out of canonical order. # Re-order by namespace ID number... - // @phan-suppress-next-line PhanTypeMismatchArgumentInternal ksort( $this->namespaceNames ); Hooks::run( 'LanguageGetNamespaces', [ &$this->namespaceNames ] ); @@ -3237,7 +3235,6 @@ 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; } } diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index d89959043d..6d6dbe503c 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -89,7 +89,11 @@ abstract class Maintenance { // Const for getStdin() const STDIN_ALL = 'all'; - // Array of desired/allowed params + /** + * Array of desired/allowed params + * @var array[] + * @phan-var array + */ protected $mParams = []; // Array of mapping short parameters to long ones @@ -128,9 +132,17 @@ abstract class Maintenance { */ protected $mBatchSize = null; - // Generic options added by addDefaultParams() + /** + * Generic options added by addDefaultParams() + * @var array[] + * @phan-var array + */ private $mGenericParameters = []; - // Generic options which might or not be supported by the script + /** + * Generic options which might or not be supported by the script + * @var array[] + * @phan-var array + */ private $mDependantParameters = []; /** diff --git a/maintenance/benchmarks/benchmarkTidy.php b/maintenance/benchmarks/benchmarkTidy.php index 558fec8ceb..357bf1b09c 100644 --- a/maintenance/benchmarks/benchmarkTidy.php +++ b/maintenance/benchmarks/benchmarkTidy.php @@ -59,6 +59,7 @@ class BenchmarkTidy extends Benchmarker { $min = $times[0]; $max = end( $times ); if ( $n % 2 ) { + // @phan-suppress-next-line PhanTypeMismatchDimFetch $median = $times[ ( $n - 1 ) / 2 ]; } else { $median = ( $times[$n / 2] + $times[$n / 2 - 1] ) / 2; diff --git a/maintenance/convertExtensionToRegistration.php b/maintenance/convertExtensionToRegistration.php index 737e65f343..409ecdf135 100644 --- a/maintenance/convertExtensionToRegistration.php +++ b/maintenance/convertExtensionToRegistration.php @@ -279,7 +279,6 @@ class ConvertExtensionToRegistration extends Maintenance { /** * @param string $realName * @param array[] $value - * @suppress PhanTypeInvalidDimOffset */ protected function handleResourceModules( $realName, $value ) { $defaults = []; diff --git a/maintenance/importImages.php b/maintenance/importImages.php index e4d1f096e0..7f8e16a6b1 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -358,7 +358,7 @@ class ImportImages extends Maintenance { # Protect the file $this->output( "\nWaiting for replica DBs...\n" ); // Wait for replica DBs. - sleep( 2.0 ); # Why this sleep? + sleep( 2 ); # Why this sleep? wfWaitForSlaves(); $this->output( "\nSetting image restrictions ... " ); diff --git a/maintenance/storage/orphanStats.php b/maintenance/storage/orphanStats.php index 60f88ba698..6a04b98a03 100644 --- a/maintenance/storage/orphanStats.php +++ b/maintenance/storage/orphanStats.php @@ -38,7 +38,7 @@ class OrphanStats extends Maintenance { "Show some statistics on the blob_orphans table, created with trackBlobs.php" ); } - protected function &getDB( $cluster, $groups = [], $wiki = false ) { + protected function getDB( $cluster, $groups = [], $wiki = false ) { $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); $lb = $lbFactory->getExternalLB( $cluster ); -- 2.20.1