From b1a5367ec8db98bd8e2e1ff24927b363dba37eb4 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sat, 12 Oct 2019 16:13:38 +0200 Subject: [PATCH] Fix new phan errors, part 7 Bug: T231636 Change-Id: Ia5e0abee7163c5a1abd0bb53b89603cc2e7a9b5c --- includes/profiler/Profiler.php | 2 +- includes/profiler/SectionProfiler.php | 2 +- includes/resourceloader/ResourceLoaderFileModule.php | 1 + includes/resourceloader/ResourceLoaderImageModule.php | 4 ++-- includes/search/SearchHighlighter.php | 3 ++- includes/session/BotPasswordSessionProvider.php | 4 ++++ includes/specials/SpecialMovepage.php | 1 + includes/user/User.php | 1 + includes/utils/ClassCollector.php | 1 + languages/LanguageConverter.php | 2 ++ maintenance/Maintenance.php | 1 + maintenance/findHooks.php | 1 + maintenance/mcc.php | 1 + maintenance/populateArchiveRevId.php | 1 + maintenance/reassignEdits.php | 1 + 15 files changed, 21 insertions(+), 5 deletions(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 2eb558603ef..513a278e8d3 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -342,7 +342,7 @@ abstract class Profiler { * entries for the cyclic invocation should be be demarked with "@". * This makes filtering them out easier and follows the xhprof style. * - * @return array List of method entries arrays, each having: + * @return array[] List of method entries arrays, each having: * - name : method name * - calls : the number of invoking calls * - real : real time elapsed (ms) diff --git a/includes/profiler/SectionProfiler.php b/includes/profiler/SectionProfiler.php index 2b9332fa9f5..f78c2548b5d 100644 --- a/includes/profiler/SectionProfiler.php +++ b/includes/profiler/SectionProfiler.php @@ -37,7 +37,7 @@ class SectionProfiler { /** @var array Queue of open profile calls with start data */ protected $workStack = []; - /** @var array Map of (function name => aggregate data array) */ + /** @var array[] Map of (function name => aggregate data array) */ protected $collated = []; /** @var bool */ protected $collateDone = false; diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index e6e5ebfc2de..ebab79f6f3d 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -1103,6 +1103,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * * @param ResourceLoaderContext $context * @return array|null + * @phan-return array{main:string,files:string[][]}|null * @throws MWException If the 'packageFiles' definition is invalid. */ private function expandPackageFiles( ResourceLoaderContext $context ) { diff --git a/includes/resourceloader/ResourceLoaderImageModule.php b/includes/resourceloader/ResourceLoaderImageModule.php index 4f06355eed4..6fd00895005 100644 --- a/includes/resourceloader/ResourceLoaderImageModule.php +++ b/includes/resourceloader/ResourceLoaderImageModule.php @@ -27,8 +27,8 @@ */ class ResourceLoaderImageModule extends ResourceLoaderModule { - /** @var array|null */ - protected $definition = null; + /** @var array */ + protected $definition; /** * Local base path, see __construct() diff --git a/includes/search/SearchHighlighter.php b/includes/search/SearchHighlighter.php index 8f0db447a15..b34631466e8 100644 --- a/includes/search/SearchHighlighter.php +++ b/includes/search/SearchHighlighter.php @@ -146,6 +146,7 @@ class SearchHighlighter { $this->splitAndAdd( $textExt, $count, substr( $text, $start ) ); break; } + '@phan-var string[] $textExt'; $all = $textExt + $otherExt; // these have disjunct key sets @@ -305,7 +306,7 @@ class SearchHighlighter { /** * Split text into lines and add it to extracts array * - * @param array &$extracts Index -> $line + * @param string[] &$extracts Index -> $line * @param int &$count * @param string $text */ diff --git a/includes/session/BotPasswordSessionProvider.php b/includes/session/BotPasswordSessionProvider.php index a588aeea530..3c5c2e586e1 100644 --- a/includes/session/BotPasswordSessionProvider.php +++ b/includes/session/BotPasswordSessionProvider.php @@ -112,6 +112,10 @@ class BotPasswordSessionProvider extends ImmutableSessionProviderWithCookie { return $session; } + /** + * @inheritDoc + * @phan-param array &$metadata + */ public function refreshSessionInfo( SessionInfo $info, WebRequest $request, &$metadata ) { $missingKeys = array_diff( [ 'centralId', 'appId', 'token' ], diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index c6a5151fb54..6a8a9906cac 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -259,6 +259,7 @@ class MovePageForm extends UnlistedSpecialPage { if ( count( $err ) == 1 ) { $errMsg = $err[0]; + '@phan-var array $errMsg'; $errMsgName = array_shift( $errMsg ); if ( $errMsgName == 'hookaborted' ) { diff --git a/includes/user/User.php b/includes/user/User.php index 78e2d2e9781..754a2bc85d9 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -2932,6 +2932,7 @@ class User implements IDBAccessObject, UserIdentity { } if ( array_key_exists( $oname, $this->mOptions ) ) { + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable Obvious false positive return $this->mOptions[$oname]; } diff --git a/includes/utils/ClassCollector.php b/includes/utils/ClassCollector.php index cf62f6d008a..344e055b2ef 100644 --- a/includes/utils/ClassCollector.php +++ b/includes/utils/ClassCollector.php @@ -129,6 +129,7 @@ class ClassCollector { * @param array|string $token */ protected function tryEndExpect( $token ) { + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable switch ( $this->startToken[0] ) { case T_DOUBLE_COLON: // Skip over T_CLASS after T_DOUBLE_COLON because this is something like diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index f42bb882041..a0c00e0388b 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -970,6 +970,8 @@ class LanguageConverter { $this->loadDefaultTables(); foreach ( $this->mVariants as $var ) { $cached = $this->parseCachedTable( $var ); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable + // FIXME: $this->mTables could theoretically be null here $this->mTables[$var]->mergeArray( $cached ); } diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 218c917c8b6..6c31561fc41 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1142,6 +1142,7 @@ abstract class Maintenance { $this->mGenericParameters, $this->mDependantParameters ); + '@phan-var array[] $scriptSpecificParams'; if ( count( $scriptSpecificParams ) > 0 ) { $this->output( "Script specific parameters:\n" ); // Parameters description diff --git a/maintenance/findHooks.php b/maintenance/findHooks.php index 6d5dda1bfca..ef4ed1859a3 100644 --- a/maintenance/findHooks.php +++ b/maintenance/findHooks.php @@ -119,6 +119,7 @@ class FindHooks extends Maintenance { // Could not get parameter information continue; } + '@phan-var array $args'; if ( count( $argsDoc ) !== count( $args ) ) { $badParameterCount[] = $hook . ': Doc: ' . count( $argsDoc ) . ' vs. Code: ' . count( $args ); } else { diff --git a/maintenance/mcc.php b/maintenance/mcc.php index e70060e2f69..c547b9794fb 100644 --- a/maintenance/mcc.php +++ b/maintenance/mcc.php @@ -165,6 +165,7 @@ do { $res = $mcc->get( $args[0] ); $hv = $mcc->_hashfunc( $args[0] ); for ( $i = 0; $i < 3; $i++ ) { + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable print $mcc->_buckets[$hv % $mcc->_bucketcount] . "\n"; $hv += $mcc->_hashfunc( $i . $args[0] ); } diff --git a/maintenance/populateArchiveRevId.php b/maintenance/populateArchiveRevId.php index 84b962af371..847d2eb385a 100644 --- a/maintenance/populateArchiveRevId.php +++ b/maintenance/populateArchiveRevId.php @@ -162,6 +162,7 @@ class PopulateArchiveRevId extends LoggedUpdateMaintenance { $revIds = $dbw->selectFieldValues( 'revision', 'rev_id', + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable [ 'rev_timestamp' => self::$dummyRev['rev_timestamp'] ], $fname ); diff --git a/maintenance/reassignEdits.php b/maintenance/reassignEdits.php index f3b856cbcfe..410b6b1df8d 100644 --- a/maintenance/reassignEdits.php +++ b/maintenance/reassignEdits.php @@ -148,6 +148,7 @@ class ReassignEdits extends Maintenance { $this->output( "Updating recent changes..." ); $dbw->update( 'recentchanges', [ 'rc_actor' => $to->getActorId( $dbw ) ], + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable False positive [ $rcQueryInfo['conds'] ], __METHOD__ ); $this->output( "done.\n" ); }