Fix new phan errors, part 3

These are almost only doc changes, with two exceptions:
1-In LinkHolderArray, int-alike array keys are now cast to int, to be uniform with what we do in other code paths
2-In ExtensionRegistration, changed a line to throw an Exception
immediately, instead of an ExtensionDependencyError. This is because the
latter takes an array with msg and type, but we were passing it a plain
string (and in fact the code was bugged).

Bug: T231636
Change-Id: I8b0ef50d279c2a87490dde6a467a4e22c0710afd
This commit is contained in:
Daimona Eaytoy 2019-10-11 16:31:51 +02:00
parent 95dc119527
commit bd5b6f98ba
19 changed files with 33 additions and 25 deletions

View file

@ -60,7 +60,8 @@ class TrackingCategories {
/**
* Read the global and extract title objects from the corresponding messages
* @return array [ 'msg' => Title, 'cats' => Title[] ]
* @return array[] [ 'msg' => Title, 'cats' => Title[] ]
* @phan-return array<string,array{msg:Title,cats:Title[]}>
*/
public function getTrackingCategories() {
$categories = array_merge(

View file

@ -1254,7 +1254,7 @@ interface IDatabase {
* errors which wouldn't have occurred in MySQL.
*
* @param string $table Table name. This will be passed through Database::tableName().
* @param array $rows A single row or list of rows to insert
* @param array|array[] $rows A single row or list of rows to insert
* @param array[]|string[]|string $uniqueIndexes All unique indexes. One of the following:
* a) the one unique field in the table (when no composite unique key exist)
* b) a list of all unique fields in the table (when no composite unique key exist)

View file

@ -72,7 +72,7 @@ abstract class VirtualRESTService {
* must be added back (with the same key) in onRequests() or onResponses();
* it's reponse may be filled in as with other requests.
*
* @param array $reqs Map of Virtual HTTP request arrays
* @param array[] $reqs Map of Virtual HTTP request arrays
* @param Closure $idGeneratorFunc Method to generate unique keys for new requests
* @return array Modified HTTP request array map
*/

View file

@ -168,7 +168,7 @@ class ProtectLogFormatter extends LogFormatter {
/**
* Create the protect description to show in the log formatter
*
* @param array $details
* @param array[] $details
* @return string
*/
public function createProtectDescription( array $details ) {

View file

@ -874,7 +874,7 @@ abstract class MediaHandler {
/**
* Converts a dimensions array about a potentially multipage document from an
* exhaustive list of ordered page numbers to a list of page ranges
* @param array $pagesByDimensions
* @param array[] $pagesByDimensions
* @return string
* @since 1.30
*/

View file

@ -117,7 +117,7 @@ class WebPHandler extends BitmapHandler {
/**
* Extracts the image size and WebP type from a file based on the chunk list
* @param array $chunks Chunks as extracted by RiffExtractor
* @param array[] $chunks Chunks as extracted by RiffExtractor
* @param string $filename
* @return array Header data array with entries 'compression', 'width' and 'height', where
* 'compression' can be 'lossy', 'lossless', 'animated' or 'unknown'

View file

@ -1166,7 +1166,8 @@ EOT
* @note This will only list several alternatives if thumbnails are rendered on 404
* @param int $origWidth Actual width of image
* @param int $origHeight Actual height of image
* @return array An array of [width, height] pairs.
* @return int[][] An array of [width, height] pairs.
* @phan-return array<int,array{0:int,1:int}>
*/
protected function getThumbSizes( $origWidth, $origHeight ) {
global $wgImageLimits;

View file

@ -27,8 +27,11 @@ use MediaWiki\MediaWikiServices;
* @ingroup Parser
*/
class LinkHolderArray {
/** @var array[][] */
public $internals = [];
/** @var array[] */
public $interwikis = [];
/** @var int */
public $size = 0;
/**
@ -180,8 +183,8 @@ class LinkHolderArray {
) {
break;
}
$ns = $m[1][0];
$key = $m[2][0];
$ns = (int)$m[1][0];
$key = (int)$m[2][0];
$sub->internals[$ns][$key] = $this->internals[$ns][$key];
$pos = $m[0][1] + strlen( $m[0][0] );
}

View file

@ -1737,7 +1737,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
/**
* Get a list of all time zones
* @param Language $language Language used for the localized names
* @return array A list of all time zones. The system name of the time zone is used as key and
* @return array[] A list of all time zones. The system name of the time zone is used as key and
* the value is an array which contains localized name, the timecorrection value used for
* preferences and the region
* @since 1.26

View file

@ -81,7 +81,7 @@ class SectionProfiler {
* delays in usage of the profiler skewing the results. A "-total" entry
* is always included in the results.
*
* @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)

View file

@ -64,7 +64,7 @@ class ExtensionDependencyError extends Exception {
public $missingAbilities = [];
/**
* @param array $errors Each error has a 'msg' and 'type' key at minimum
* @param array[] $errors Each error has a 'msg' and 'type' key at minimum
*/
public function __construct( array $errors ) {
$msg = '';

View file

@ -271,7 +271,6 @@ class ExtensionRegistry {
$processor = new ExtensionProcessor();
$versionChecker = $this->buildVersionChecker();
$extDependencies = [];
$incompatible = [];
$warnings = false;
foreach ( $queue as $path => $mtime ) {
$json = file_get_contents( $path );
@ -294,7 +293,7 @@ class ExtensionRegistry {
}
$version = $info['manifest_version'];
if ( $version < self::OLDEST_MANIFEST_VERSION || $version > self::MANIFEST_VERSION ) {
$incompatible[] = "$path: unsupported manifest_version: {$version}";
throw new Exception( "$path: unsupported manifest_version: {$version}" );
}
$dir = dirname( $path );
@ -323,12 +322,9 @@ class ExtensionRegistry {
$data['warnings'] = $warnings;
// check for incompatible extensions
$incompatible = array_merge(
$incompatible,
$versionChecker
->setLoadedExtensionsAndSkins( $data['credits'] )
->checkArray( $extDependencies )
);
$incompatible = $versionChecker
->setLoadedExtensionsAndSkins( $data['credits'] )
->checkArray( $extDependencies );
if ( $incompatible ) {
throw new ExtensionDependencyError( $incompatible );

View file

@ -1435,13 +1435,16 @@ MESSAGE;
*
* @internal For use by ResourceLoaderStartUpModule only
* @param ResourceLoaderContext $context
* @param array $modules Array of module registration arrays, each containing
* @param array[] $modules Array of module registration arrays, each containing
* - string: module name
* - string: module version
* - array|null: List of dependencies (optional)
* - string|null: Module group (optional)
* - string|null: Name of foreign module source, or 'local' (optional)
* - string|null: Script body of a skip function (optional)
* @codingStandardsIgnoreStart
* @phan-param array<int,array{0:string,1:string,2?:?array,3?:?string,4?:?string,5?:?string}> $modules
* @codingStandardsIgnoreEnd
* @return string JavaScript code
*/
public static function makeLoaderRegisterScript(

View file

@ -35,7 +35,8 @@ class SearchEngineConfig {
/**
* Make a list of searchable namespaces and their canonical names.
* @return array Namespace ID => name
* @return string[] Namespace ID => name
* @phan-return array<int,string>
*/
public function searchableNamespaces() {
$arr = [];

View file

@ -136,7 +136,7 @@ class MovePageForm extends UnlistedSpecialPage {
/**
* Show the form
*
* @param array $err Error messages. Each item is an error message.
* @param (string|array)[] $err Error messages. Each item is an error message.
* It may either be a string message name or array message name and
* parameters, like the second argument to OutputPage::wrapWikiMsg().
* @param bool $isPermError Whether the error message is about user permissions.

View file

@ -33,6 +33,7 @@ class SpecialNewpages extends IncludableSpecialPage {
* @var FormOptions
*/
protected $opts;
/** @var array[] */
protected $customFilters;
protected $showNavigation = false;

View file

@ -682,7 +682,8 @@ class SpecialSearch extends SpecialPage {
}
/**
* @return array
* @return array[]
* @phan-return array<string,array{message:string,tooltip:string,namespaces:int|string|(int|string)[],namespace-messages?:string[]}>
*/
protected function getSearchProfiles() {
// Builds list of Search Types (profiles)

View file

@ -95,6 +95,7 @@ class BlockListPager extends TablePager {
$msg[$key] = $this->msg( $key )->text();
}
}
'@phan-var string[] $msg';
/** @var object $row */
$row = $this->mCurrentRow;

View file

@ -2357,7 +2357,7 @@ class User implements IDBAccessObject, UserIdentity {
* If there are no new messages, it returns an empty array.
* @note This function was designed to accomodate multiple talk pages, but
* currently only returns a single link and revision.
* @return array
* @return array[]
*/
public function getNewMessageLinks() {
// Avoid PHP 7.1 warning of passing $this by reference