Fix and improve PHPDoc type hints in FileBackend and FileRepo
authorThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Thu, 19 Apr 2018 08:30:33 +0000 (10:30 +0200)
committerThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Thu, 19 Apr 2018 08:32:09 +0000 (10:32 +0200)
Change-Id: I311b4a6777946b451d70c6fdb2133dbbd73f159f

13 files changed:
includes/filebackend/FileBackendGroup.php
includes/filebackend/filejournal/DBFileJournal.php
includes/filerepo/FileBackendDBRepoWrapper.php
includes/filerepo/FileRepo.php
includes/filerepo/ForeignAPIRepo.php
includes/filerepo/LocalRepo.php
includes/filerepo/RepoGroup.php
includes/filerepo/file/ArchivedFile.php
includes/filerepo/file/File.php
includes/filerepo/file/ForeignAPIFile.php
includes/filerepo/file/ForeignDBFile.php
includes/filerepo/file/LocalFile.php
includes/filerepo/file/OldLocalFile.php

index 9239c6c..454b633 100644 (file)
@@ -112,7 +112,7 @@ class FileBackendGroup {
        /**
         * Register an array of file backend configurations
         *
-        * @param array $configs
+        * @param array[] $configs
         * @param string|null $readOnlyReason
         * @throws InvalidArgumentException
         */
index 4269f91..3dc9f18 100644 (file)
@@ -124,9 +124,9 @@ class DBFileJournal extends FileJournal {
 
        /**
         * @see FileJournal::doGetChangeEntries()
-        * @param int $start
+        * @param int|null $start
         * @param int $limit
-        * @return array
+        * @return array[]
         */
        protected function doGetChangeEntries( $start, $limit ) {
                $dbw = $this->getMasterDB();
index 21b7ac2..dbb5421 100644 (file)
@@ -92,9 +92,9 @@ class FileBackendDBRepoWrapper extends FileBackend {
         * E.g. mwstore://local-backend/local-public/a/ab/<name>.jpg
         * => mwstore://local-backend/local-original/x/y/z/<sha1>.jpg
         *
-        * @param array $paths
+        * @param string[] $paths
         * @param bool $latest
-        * @return array Translated paths in same order
+        * @return string[] Translated paths in same order
         */
        public function getBackendPaths( array $paths, $latest = true ) {
                $db = $this->getDB( $latest ? DB_MASTER : DB_REPLICA );
@@ -341,8 +341,8 @@ class FileBackendDBRepoWrapper extends FileBackend {
         *
         * This leaves destination paths alone since we don't want those to mutate
         *
-        * @param array $ops
-        * @return array
+        * @param array[] $ops
+        * @return array[]
         */
        protected function mungeOpPaths( array $ops ) {
                // Ops that use 'src' and do not mutate core file data there
index a67e3d6..28021ef 100644 (file)
@@ -578,8 +578,8 @@ class FileRepo {
         * Get an array of arrays or iterators of file objects for files that
         * have the given SHA-1 content hashes.
         *
-        * @param array $hashes An array of hashes
-        * @return array An Array of arrays or iterators of file objects and the hash as key
+        * @param string[] $hashes An array of hashes
+        * @return array[] An Array of arrays or iterators of file objects and the hash as key
         */
        public function findBySha1s( array $hashes ) {
                $result = [];
@@ -599,7 +599,7 @@ class FileRepo {
         * STUB
         * @param string $prefix The prefix to search for
         * @param int $limit The maximum amount of files to return
-        * @return array
+        * @return LocalFile[]
         */
        public function findFilesByPrefix( $prefix, $limit ) {
                return [];
@@ -789,7 +789,7 @@ class FileRepo {
         * should use File::getDescriptionText().
         *
         * @param string $name Name of image to fetch
-        * @param string $lang Language to fetch it in, if any.
+        * @param string|null $lang Language to fetch it in, if any.
         * @return string|false
         */
        public function getDescriptionRenderUrl( $name, $lang = null ) {
@@ -928,7 +928,7 @@ class FileRepo {
         * Each file can be a (zone, rel) pair, virtual url, storage path.
         * It will try to delete each file, but ignores any errors that may occur.
         *
-        * @param array $files List of files to delete
+        * @param string[] $files List of files to delete
         * @param int $flags Bitwise combination of the following flags:
         *   self::SKIP_LOCKING      Skip any file locking when doing the deletions
         * @return Status
@@ -1378,7 +1378,7 @@ class FileRepo {
        /**
         * Checks existence of an array of files.
         *
-        * @param array $files Virtual URLs (or storage paths) of files to check
+        * @param string[] $files Virtual URLs (or storage paths) of files to check
         * @return array Map of files and existence flags, or false
         */
        public function fileExistsBatch( array $files ) {
@@ -1484,7 +1484,7 @@ class FileRepo {
         * Delete files in the deleted directory if they are not referenced in the filearchive table
         *
         * STUB
-        * @param array $storageKeys
+        * @param string[] $storageKeys
         */
        public function cleanupDeletedBatch( array $storageKeys ) {
                $this->assertWritableRepo();
@@ -1700,7 +1700,7 @@ class FileRepo {
        /**
         * Get a callback function to use for cleaning error message parameters
         *
-        * @return array
+        * @return string[]
         */
        function getErrorCleanupFunction() {
                switch ( $this->pathDisclosureProtection ) {
@@ -1889,7 +1889,7 @@ class FileRepo {
        /**
         * Get an UploadStash associated with this repo.
         *
-        * @param User $user
+        * @param User|null $user
         * @return UploadStash
         */
        public function getUploadStash( User $user = null ) {
index 1a86648..06b21a8 100644 (file)
@@ -120,7 +120,7 @@ class ForeignAPIRepo extends FileRepo {
        }
 
        /**
-        * @param array $files
+        * @param string[] $files
         * @return array
         */
        function fileExistsBatch( array $files ) {
@@ -176,7 +176,7 @@ class ForeignAPIRepo extends FileRepo {
 
        /**
         * @param string $virtualUrl
-        * @return bool
+        * @return false
         */
        function getFileProps( $virtualUrl ) {
                return false;
@@ -231,7 +231,7 @@ class ForeignAPIRepo extends FileRepo {
 
        /**
         * @param string $hash
-        * @return array
+        * @return ForeignAPIFile[]
         */
        function findBySha1( $hash ) {
                $results = $this->fetchImageQuery( [
@@ -257,10 +257,10 @@ class ForeignAPIRepo extends FileRepo {
         * @param string $name
         * @param int $width
         * @param int $height
-        * @param array &$result
+        * @param array|null &$result Output-only parameter, guaranteed to become an array
         * @param string $otherParams
         *
-        * @return bool
+        * @return string|false
         */
        function getThumbUrl( $name, $width = -1, $height = -1, &$result = null, $otherParams = '' ) {
                $data = $this->fetchImageQuery( [
@@ -287,7 +287,7 @@ class ForeignAPIRepo extends FileRepo {
         * @param int $width
         * @param int $height
         * @param string $otherParams
-        * @param string $lang Language code for language of error
+        * @param string|null $lang Language code for language of error
         * @return bool|MediaTransformError
         * @since 1.22
         */
index 1bf5346..76043d5 100644 (file)
@@ -91,7 +91,7 @@ class LocalRepo extends FileRepo {
         * interleave database locks with file operations, which is potentially a
         * remote operation.
         *
-        * @param array $storageKeys
+        * @param string[] $storageKeys
         *
         * @return Status
         */
@@ -371,7 +371,7 @@ class LocalRepo extends FileRepo {
         * SHA-1 content hash.
         *
         * @param string $hash A sha1 hash to look for
-        * @return File[]
+        * @return LocalFile[]
         */
        function findBySha1( $hash ) {
                $dbr = $this->getReplicaDB();
@@ -400,8 +400,8 @@ class LocalRepo extends FileRepo {
         *
         * Overrides generic implementation in FileRepo for performance reason
         *
-        * @param array $hashes An array of hashes
-        * @return array An Array of arrays or iterators of file objects and the hash as key
+        * @param string[] $hashes An array of hashes
+        * @return array[] An Array of arrays or iterators of file objects and the hash as key
         */
        function findBySha1s( array $hashes ) {
                if ( !count( $hashes ) ) {
@@ -434,7 +434,7 @@ class LocalRepo extends FileRepo {
         *
         * @param string $prefix The prefix to search for
         * @param int $limit The maximum amount of files to return
-        * @return array
+        * @return LocalFile[]
         */
        public function findFilesByPrefix( $prefix, $limit ) {
                $selectOptions = [ 'ORDER BY' => 'img_name', 'LIMIT' => intval( $limit ) ];
index 24d1ab2..b797790 100644 (file)
@@ -423,7 +423,7 @@ class RepoGroup {
         * Split a virtual URL into repo, zone and rel parts
         * @param string $url
         * @throws MWException
-        * @return array Containing repo, zone and rel
+        * @return string[] Containing repo, zone and rel
         */
        function splitVirtualUrl( $url ) {
                if ( substr( $url, 0, 9 ) != 'mwrepo://' ) {
index 982fea4..d9763c6 100644 (file)
@@ -214,7 +214,7 @@ class ArchivedFile {
        /**
         * Fields in the filearchive table
         * @deprecated since 1.31, use self::getQueryInfo() instead.
-        * @return array
+        * @return string[]
         */
        static function selectFields() {
                global $wgActorTableSchemaMigrationStage;
@@ -258,7 +258,7 @@ class ArchivedFile {
         * Return the tables, fields, and join conditions to be selected to create
         * a new archivedfile object.
         * @since 1.31
-        * @return array With three keys:
+        * @return array[] With three keys:
         *   - tables: (string[]) to include in the `$table` to `IDatabase->select()`
         *   - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
index d4605d3..cfd1cf2 100644 (file)
@@ -268,7 +268,7 @@ abstract class File implements IDBAccessObject {
         * a two-part name, set the minor type to 'unknown'.
         *
         * @param string $mime "text/html" etc
-        * @return array ("text", "html") etc
+        * @return string[] ("text", "html") etc
         */
        public static function splitMime( $mime ) {
                if ( strpos( $mime, '/' ) !== false ) {
@@ -569,7 +569,7 @@ abstract class File implements IDBAccessObject {
         * format does not support that sort of thing, returns
         * an empty array.
         *
-        * @return array
+        * @return string[]
         * @since 1.23
         */
        public function getAvailableLanguages() {
@@ -1423,7 +1423,7 @@ abstract class File implements IDBAccessObject {
         * Get all thumbnail names previously generated for this file
         * STUB
         * Overridden by LocalFile
-        * @return array
+        * @return string[]
         */
        function getThumbnails() {
                return [];
@@ -1474,9 +1474,9 @@ abstract class File implements IDBAccessObject {
         * Return a fragment of the history of file.
         *
         * STUB
-        * @param int $limit Limit of rows to return
-        * @param string $start Only revisions older than $start will be returned
-        * @param string $end Only revisions newer than $end will be returned
+        * @param int|null $limit Limit of rows to return
+        * @param string|int|null $start Only revisions older than $start will be returned
+        * @param string|int|null $end Only revisions newer than $end will be returned
         * @param bool $inc Include the endpoints of the time range
         *
         * @return File[]
@@ -2099,9 +2099,9 @@ abstract class File implements IDBAccessObject {
         *   File::FOR_PUBLIC       to be displayed to all users
         *   File::FOR_THIS_USER    to be displayed to the given user
         *   File::RAW              get the description regardless of permissions
-        * @param User $user User object to check for, only if FOR_THIS_USER is
+        * @param User|null $user User object to check for, only if FOR_THIS_USER is
         *   passed to the $audience parameter
-        * @return string
+        * @return null|string
         */
        function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
                return null;
@@ -2161,7 +2161,7 @@ abstract class File implements IDBAccessObject {
         * field of this file, if it's marked as deleted.
         * STUB
         * @param int $field
-        * @param User $user User object to check, or null to use $wgUser
+        * @param User|null $user User object to check, or null to use $wgUser
         * @return bool
         */
        function userCan( $field, User $user = null ) {
@@ -2177,7 +2177,7 @@ abstract class File implements IDBAccessObject {
        }
 
        /**
-        * @return array HTTP header name/value map to use for HEAD/GET request responses
+        * @return string[] HTTP header name/value map to use for HEAD/GET request responses
         * @since 1.30
         */
        function getContentHeaders() {
index 2a40942..be88b49 100644 (file)
@@ -192,8 +192,8 @@ class ForeignAPIFile extends File {
        }
 
        /**
-        * @param array $metadata
-        * @return array
+        * @param mixed $metadata
+        * @return mixed
         */
        public static function parseMetadata( $metadata ) {
                if ( !is_array( $metadata ) ) {
@@ -254,7 +254,7 @@ class ForeignAPIFile extends File {
 
        /**
         * @param int $audience
-        * @param User $user
+        * @param User|null $user
         * @return null|string
         */
        public function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
@@ -333,7 +333,7 @@ class ForeignAPIFile extends File {
        }
 
        /**
-        * @return array
+        * @return string[]
         */
        function getThumbnails() {
                $dir = $this->getThumbPath( $this->getName() );
index cf21161..388e950 100644 (file)
@@ -74,7 +74,7 @@ class ForeignDBFile extends LocalFile {
         * @param string $source
         * @param bool $watch
         * @param bool|string $timestamp
-        * @param User $user User object or null to use $wgUser
+        * @param User|null $user User object or null to use $wgUser
         * @return bool
         * @throws MWException
         */
index 0464f07..cff1044 100644 (file)
@@ -141,7 +141,7 @@ class LocalFile extends File {
         * @param FileRepo $repo
         * @param null $unused
         *
-        * @return LocalFile
+        * @return self
         */
        static function newFromTitle( $title, $repo, $unused = null ) {
                return new self( $title, $repo );
@@ -154,7 +154,7 @@ class LocalFile extends File {
         * @param stdClass $row
         * @param FileRepo $repo
         *
-        * @return LocalFile
+        * @return self
         */
        static function newFromRow( $row, $repo ) {
                $title = Title::makeTitle( NS_FILE, $row->img_name );
@@ -195,7 +195,7 @@ class LocalFile extends File {
        /**
         * Fields in the image table
         * @deprecated since 1.31, use self::getQueryInfo() instead.
-        * @return array
+        * @return string[]
         */
        static function selectFields() {
                global $wgActorTableSchemaMigrationStage;
@@ -235,7 +235,7 @@ class LocalFile extends File {
         * @since 1.31
         * @param string[] $options
         *   - omit-lazy: Omit fields that are lazily cached.
-        * @return array With three keys:
+        * @return array[] With three keys:
         *   - tables: (string[]) to include in the `$table` to `IDatabase->select()`
         *   - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
@@ -405,7 +405,7 @@ class LocalFile extends File {
        /**
         * Returns the list of object properties that are included as-is in the cache.
         * @param string $prefix Must be the empty string
-        * @return array
+        * @return string[]
         * @since 1.31 No longer accepts a non-empty $prefix
         */
        protected function getCacheFields( $prefix = 'img_' ) {
@@ -427,7 +427,7 @@ class LocalFile extends File {
         * Returns the list of object properties that are included as-is in the
         * cache, only when they're not too big, and are lazily loaded by self::loadExtraFromDB().
         * @param string $prefix Must be the empty string
-        * @return array
+        * @return string[]
         * @since 1.31 No longer accepts a non-empty $prefix
         */
        protected function getLazyCacheFields( $prefix = 'img_' ) {
@@ -500,7 +500,7 @@ class LocalFile extends File {
        /**
         * @param IDatabase $dbr
         * @param string $fname
-        * @return array|bool
+        * @return string[]|bool
         */
        private function loadExtraFieldsWithTimestamp( $dbr, $fname ) {
                $fieldMap = false;
@@ -1160,9 +1160,9 @@ class LocalFile extends File {
        /** purgeEverything inherited */
 
        /**
-        * @param int $limit Optional: Limit to number of results
-        * @param int $start Optional: Timestamp, start from
-        * @param int $end Optional: Timestamp, end at
+        * @param int|null $limit Optional: Limit to number of results
+        * @param string|int|null $start Optional: Timestamp, start from
+        * @param string|int|null $end Optional: Timestamp, end at
         * @param bool $inc
         * @return OldLocalFile[]
         */
@@ -2105,8 +2105,8 @@ class LocalFile extends File {
         * This is not used by ImagePage for local files, since (among other things)
         * it skips the parser cache.
         *
-        * @param Language $lang What language to get description in (Optional)
-        * @return bool|mixed
+        * @param Language|null $lang What language to get description in (Optional)
+        * @return string|false
         */
        function getDescriptionText( $lang = null ) {
                $revision = Revision::newFromTitle( $this->title, false, Revision::READ_NORMAL );
@@ -2124,7 +2124,7 @@ class LocalFile extends File {
 
        /**
         * @param int $audience
-        * @param User $user
+        * @param User|null $user
         * @return string
         */
        function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
@@ -2369,7 +2369,7 @@ class LocalFileDeleteBatch {
 
        /**
         * Add the old versions of the image to the batch
-        * @return array List of archive names from old versions
+        * @return string[] List of archive names from old versions
         */
        public function addOlds() {
                $archiveNames = [];
@@ -2762,10 +2762,10 @@ class LocalFileRestoreBatch {
        /** @var LocalFile */
        private $file;
 
-       /** @var array List of file IDs to restore */
+       /** @var string[] List of file IDs to restore */
        private $cleanupBatch;
 
-       /** @var array List of file IDs to restore */
+       /** @var string[] List of file IDs to restore */
        private $ids;
 
        /** @var bool Add all revisions of the file */
@@ -2780,7 +2780,7 @@ class LocalFileRestoreBatch {
         */
        function __construct( File $file, $unsuppress = false ) {
                $this->file = $file;
-               $this->cleanupBatch = $this->ids = [];
+               $this->cleanupBatch = [];
                $this->ids = [];
                $this->unsuppress = $unsuppress;
        }
@@ -3097,8 +3097,8 @@ class LocalFileRestoreBatch {
 
        /**
         * Removes non-existent files from a cleanup batch.
-        * @param array $batch
-        * @return array
+        * @param string[] $batch
+        * @return string[]
         */
        protected function removeNonexistentFromCleanup( $batch ) {
                $files = $newBatch = [];
@@ -3142,7 +3142,7 @@ class LocalFileRestoreBatch {
         * rollback by removing all items that were succesfully copied.
         *
         * @param Status $storeStatus
-        * @param array $storeBatch
+        * @param array[] $storeBatch
         */
        protected function cleanupFailedBatch( $storeStatus, $storeBatch ) {
                $cleanupBatch = [];
@@ -3208,7 +3208,7 @@ class LocalFileMoveBatch {
 
        /**
         * Add the old versions of the image to the batch
-        * @return array List of archive names from old versions
+        * @return string[] List of archive names from old versions
         */
        public function addOlds() {
                $archiveBase = 'archive';
@@ -3409,7 +3409,7 @@ class LocalFileMoveBatch {
 
        /**
         * Generate triplets for FileRepo::storeBatch().
-        * @return array
+        * @return array[]
         */
        protected function getMoveTriplets() {
                $moves = array_merge( [ $this->cur ], $this->olds );
@@ -3461,7 +3461,7 @@ class LocalFileMoveBatch {
        /**
         * Cleanup a partially moved array of triplets by deleting the target
         * files. Called if something went wrong half way.
-        * @param array $triplets
+        * @param array[] $triplets
         */
        protected function cleanupTarget( $triplets ) {
                // Create dest pairs from the triplets
@@ -3477,7 +3477,7 @@ class LocalFileMoveBatch {
        /**
         * Cleanup a fully moved array of triplets by deleting the source files.
         * Called at the end of the move process if everything else went ok.
-        * @param array $triplets
+        * @param array[] $triplets
         */
        protected function cleanupSource( $triplets ) {
                // Create source file names from the triplets
index 65f0fb1..3a6b879 100644 (file)
@@ -27,7 +27,7 @@
  * @ingroup FileAbstraction
  */
 class OldLocalFile extends LocalFile {
-       /** @var string Timestamp */
+       /** @var string|int Timestamp */
        protected $requestedTime;
 
        /** @var string Archive name */
@@ -39,8 +39,8 @@ class OldLocalFile extends LocalFile {
        /**
         * @param Title $title
         * @param FileRepo $repo
-        * @param null|int $time Timestamp or null
-        * @return OldLocalFile
+        * @param string|int $time
+        * @return self
         * @throws MWException
         */
        static function newFromTitle( $title, $repo, $time = null ) {
@@ -56,7 +56,7 @@ class OldLocalFile extends LocalFile {
         * @param Title $title
         * @param FileRepo $repo
         * @param string $archiveName
-        * @return OldLocalFile
+        * @return self
         */
        static function newFromArchiveName( $title, $repo, $archiveName ) {
                return new self( $title, $repo, null, $archiveName );
@@ -65,7 +65,7 @@ class OldLocalFile extends LocalFile {
        /**
         * @param stdClass $row
         * @param FileRepo $repo
-        * @return OldLocalFile
+        * @return self
         */
        static function newFromRow( $row, $repo ) {
                $title = Title::makeTitle( NS_FILE, $row->oi_name );
@@ -107,7 +107,7 @@ class OldLocalFile extends LocalFile {
        /**
         * Fields in the oldimage table
         * @deprecated since 1.31, use self::getQueryInfo() instead.
-        * @return array
+        * @return string[]
         */
        static function selectFields() {
                global $wgActorTableSchemaMigrationStage;
@@ -149,7 +149,7 @@ class OldLocalFile extends LocalFile {
         * @since 1.31
         * @param string[] $options
         *   - omit-lazy: Omit fields that are lazily cached.
-        * @return array With three keys:
+        * @return array[] With three keys:
         *   - tables: (string[]) to include in the `$table` to `IDatabase->select()`
         *   - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
@@ -191,8 +191,8 @@ class OldLocalFile extends LocalFile {
        /**
         * @param Title $title
         * @param FileRepo $repo
-        * @param string $time Timestamp or null to load by archive name
-        * @param string $archiveName Archive name or null to load by timestamp
+        * @param string|int|null $time Timestamp or null to load by archive name
+        * @param string|null $archiveName Archive name or null to load by timestamp
         * @throws MWException
         */
        function __construct( $title, $repo, $time, $archiveName ) {