From fb3428eb8f16235269fb34a98fab664c3732cba2 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Thu, 29 Aug 2019 15:19:39 +0200 Subject: [PATCH] Unsuppress other phan issues with low count And also update approximated counts, which for the most part are lower than reported (hooray!) Bug: T231636 Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd --- .phan/config.php | 42 +++++++------------ includes/EditPage.php | 2 +- includes/Title.php | 1 + includes/cache/BacklinkCache.php | 4 +- includes/filerepo/file/File.php | 4 +- includes/filerepo/file/LocalFile.php | 4 +- .../filerepo/file/UnregisteredLocalFile.php | 4 +- includes/historyblob/DiffHistoryBlob.php | 2 +- includes/language/Message.php | 2 + includes/libs/mime/MSCompoundFileReader.php | 11 +++++ includes/libs/rdbms/database/IDatabase.php | 2 +- includes/libs/stats/SamplingStatsdClient.php | 4 +- includes/objectcache/ObjectCache.php | 1 + includes/page/ImageHistoryPseudoPager.php | 2 +- includes/parser/PPDPart.php | 3 ++ includes/parser/PPDPart_Hash.php | 3 ++ includes/parser/PPDStackElement_Hash.php | 1 + includes/parser/Parser.php | 1 + includes/rcfeed/FormattedRCFeed.php | 1 + .../DerivativeResourceLoaderContext.php | 1 + .../ResourceLoaderOOUIImageModule.php | 2 +- .../specialpage/ChangesListSpecialPage.php | 2 +- .../specialpage/LoginSignupSpecialPage.php | 1 + .../specials/pagers/AllMessagesTablePager.php | 2 +- includes/user/User.php | 2 + includes/utils/AvroValidator.php | 1 + languages/Language.php | 1 + languages/LanguageConverter.php | 1 + maintenance/includes/TextPassDumper.php | 1 + maintenance/mergeMessageFileList.php | 1 + 30 files changed, 66 insertions(+), 43 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 5813b29468..893eebb418 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -76,47 +76,37 @@ $cfg['exclude_analysis_directory_list'] = [ ]; $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ - // approximate error count: 18 + // approximate error count: 22 "PhanAccessMethodInternal", - // approximate error count: 17 - "PhanCommentParamOnEmptyParamList", - // approximate error count: 29 + // approximate error count: 22 "PhanCommentParamWithoutRealParam", - // approximate error count: 21 + // approximate error count: 19 "PhanParamReqAfterOpt", - // approximate error count: 26 + // approximate error count: 20 "PhanParamSignatureMismatch", - // approximate error count: 127 + // approximate error count: 110 "PhanParamTooMany", - // approximate error count: 30 + // approximate error count: 63 "PhanTypeArraySuspicious", - // approximate error count: 27 + // approximate error count: 28 "PhanTypeArraySuspiciousNullable", - // approximate error count: 26 + // approximate error count: 22 "PhanTypeComparisonFromArray", - // approximate error count: 63 + // approximate error count: 88 "PhanTypeInvalidDimOffset", - // approximate error count: 154 + // approximate error count: 60 "PhanTypeMismatchArgument", - // approximate error count: 27 + // approximate error count: 20 "PhanTypeMismatchArgumentInternal", - // approximate error count: 27 - "PhanTypeMismatchDimFetch", - // approximate error count: 10 - "PhanTypeMismatchForeach", - // approximate error count: 77 + // approximate error count: 40 "PhanTypeMismatchProperty", - // approximate error count: 84 - "PhanTypeMismatchReturn", - // approximate error count: 12 - "PhanTypeObjectUnsetDeclaredProperty", - // approximate error count: 22 + // approximate error count: 36 "PhanUndeclaredConstant", - // approximate error count: 237 + // approximate error count: 219 "PhanUndeclaredMethod", - // approximate error count: 846 + // approximate error count: 752 "PhanUndeclaredProperty", - // approximate error count: 55 + // approximate error count: 53 "PhanUndeclaredVariableDim", ] ); diff --git a/includes/EditPage.php b/includes/EditPage.php index e51fc52bd7..f066a611a1 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1127,7 +1127,7 @@ class EditPage { * @return string|null */ protected function importContentFormData( &$request ) { - return; // Don't do anything, EditPage already extracted wpTextbox1 + return null; // Don't do anything, EditPage already extracted wpTextbox1 } /** diff --git a/includes/Title.php b/includes/Title.php index 96f196fe9b..8c5bbdc221 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1250,6 +1250,7 @@ class Title implements LinkTarget, IDBAccessObject { * @param int|int[] $namespaces,... The namespaces to check for * @return bool * @since 1.19 + * @suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, T191668#5263929 */ public function inNamespaces( /* ... */ ) { $namespaces = func_get_args(); diff --git a/includes/cache/BacklinkCache.php b/includes/cache/BacklinkCache.php index c2fb52afdc..269630276f 100644 --- a/includes/cache/BacklinkCache.php +++ b/includes/cache/BacklinkCache.php @@ -135,7 +135,7 @@ class BacklinkCache { $this->partitionCache = []; $this->fullResultCache = []; $this->wanCache->touchCheckKey( $this->makeCheckKey() ); - unset( $this->db ); + $this->db = null; } /** @@ -153,7 +153,7 @@ class BacklinkCache { * @return IDatabase */ protected function getDB() { - if ( !isset( $this->db ) ) { + if ( $this->db === null ) { $this->db = wfGetDB( DB_REPLICA ); } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 5f6a0cbcd7..d14e0ded00 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -305,7 +305,7 @@ abstract class File implements IDBAccessObject { * @return string */ public function getName() { - if ( !isset( $this->name ) ) { + if ( $this->name === null ) { $this->assertRepoDefined(); $this->name = $this->repo->getNameFromTitle( $this->title ); } @@ -1521,7 +1521,7 @@ abstract class File implements IDBAccessObject { * @return string */ function getHashPath() { - if ( !isset( $this->hashPath ) ) { + if ( $this->hashPath === null ) { $this->assertRepoDefined(); $this->hashPath = $this->repo->getHashPath( $this->getName() ); } diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 6143c3188e..f3116e2d2a 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1946,8 +1946,8 @@ class LocalFile extends File { // Now switch the object $this->title = $target; // Force regeneration of the name and hashpath - unset( $this->name ); - unset( $this->hashPath ); + $this->name = null; + $this->hashPath = null; } return $status; diff --git a/includes/filerepo/file/UnregisteredLocalFile.php b/includes/filerepo/file/UnregisteredLocalFile.php index 2865ce5eff..4292ea0ace 100644 --- a/includes/filerepo/file/UnregisteredLocalFile.php +++ b/includes/filerepo/file/UnregisteredLocalFile.php @@ -43,7 +43,7 @@ class UnregisteredLocalFile extends File { /** @var bool|string */ protected $mime; - /** @var array Dimension data */ + /** @var array[]|bool[] Dimension data */ protected $dims; /** @var bool|string Handler-specific metadata which will be saved in the img_metadata field */ @@ -108,7 +108,7 @@ class UnregisteredLocalFile extends File { /** * @param int $page - * @return bool + * @return array|bool */ private function cachePageDimensions( $page = 1 ) { $page = (int)$page; diff --git a/includes/historyblob/DiffHistoryBlob.php b/includes/historyblob/DiffHistoryBlob.php index 8d92fe5312..fdb3dc4daa 100644 --- a/includes/historyblob/DiffHistoryBlob.php +++ b/includes/historyblob/DiffHistoryBlob.php @@ -333,7 +333,7 @@ class DiffHistoryBlob implements HistoryBlob { // addItem() doesn't work if mItems is partially filled from mDiffs $this->mFrozen = true; $info = unserialize( gzinflate( $this->mCompressed ) ); - unset( $this->mCompressed ); + $this->mCompressed = null; if ( !$info ) { // Empty object diff --git a/includes/language/Message.php b/includes/language/Message.php index 12007faf87..0c1ef1388d 100644 --- a/includes/language/Message.php +++ b/includes/language/Message.php @@ -158,6 +158,8 @@ use MediaWiki\MediaWikiServices; * @see https://www.mediawiki.org/wiki/Localisation * * @since 1.17 + * @phan-file-suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, + * T191668#5263929 */ class Message implements MessageSpecifier, Serializable { /** Use message text as-is */ diff --git a/includes/libs/mime/MSCompoundFileReader.php b/includes/libs/mime/MSCompoundFileReader.php index 26e9685166..34d612abbd 100644 --- a/includes/libs/mime/MSCompoundFileReader.php +++ b/includes/libs/mime/MSCompoundFileReader.php @@ -178,11 +178,22 @@ class MSCompoundFileReader { ); } + /** + * @param int $offset + * @param int[] $struct + * @return array + */ private function unpackOffset( $offset, $struct ) { $block = $this->readOffset( $offset, array_sum( $struct ) ); return $this->unpack( $block, 0, $struct ); } + /** + * @param string $block + * @param int $offset + * @param int[] $struct + * @return array + */ private function unpack( $block, $offset, $struct ) { $data = []; foreach ( $struct as $key => $length ) { diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php index b4eb89aff4..68735e9d94 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -959,7 +959,7 @@ interface IDatabase { * @param array $valuedata * @param string $valuename * - * @return string + * @return array|string * @deprecated Since 1.33 */ public function aggregateValue( $valuedata, $valuename = 'value' ); diff --git a/includes/libs/stats/SamplingStatsdClient.php b/includes/libs/stats/SamplingStatsdClient.php index 6494c26302..172ead3812 100644 --- a/includes/libs/stats/SamplingStatsdClient.php +++ b/includes/libs/stats/SamplingStatsdClient.php @@ -84,7 +84,7 @@ class SamplingStatsdClient extends StatsdClient { $data = [ $data ]; } if ( !$data ) { - return; + return 0; } foreach ( $data as $item ) { if ( !( $item instanceof StatsdDataInterface ) ) { @@ -109,7 +109,7 @@ class SamplingStatsdClient extends StatsdClient { try { $fp = $this->getSender()->open(); if ( !$fp ) { - return; + return 0; } foreach ( $data as $message ) { $written += $this->getSender()->write( $fp, $message ); diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 8ffe824f79..5e99ac9d70 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -319,6 +319,7 @@ class ObjectCache { * @param array $params * @return WANObjectCache * @throws UnexpectedValueException + * @suppress PhanTypeMismatchReturn */ public static function newWANCacheFromParams( array $params ) { global $wgCommandLineMode, $wgSecretKey; diff --git a/includes/page/ImageHistoryPseudoPager.php b/includes/page/ImageHistoryPseudoPager.php index 799c33ad90..17a6d51a0b 100644 --- a/includes/page/ImageHistoryPseudoPager.php +++ b/includes/page/ImageHistoryPseudoPager.php @@ -77,7 +77,7 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager { } public function getQueryInfo() { - return false; + return []; } /** diff --git a/includes/parser/PPDPart.php b/includes/parser/PPDPart.php index 187373052c..b56527ac6a 100644 --- a/includes/parser/PPDPart.php +++ b/includes/parser/PPDPart.php @@ -33,6 +33,9 @@ class PPDPart { // commentEnd Past-the-end input pointer for the last comment encountered // visualEnd Past-the-end input pointer for the end of the accumulator minus comments + /** + * @param string $out + */ public function __construct( $out = '' ) { $this->out = $out; } diff --git a/includes/parser/PPDPart_Hash.php b/includes/parser/PPDPart_Hash.php index 7507f06fe0..327dd77a68 100644 --- a/includes/parser/PPDPart_Hash.php +++ b/includes/parser/PPDPart_Hash.php @@ -25,6 +25,9 @@ // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PPDPart_Hash extends PPDPart { + /** + * @param string $out + */ public function __construct( $out = '' ) { if ( $out !== '' ) { $accum = [ $out ]; diff --git a/includes/parser/PPDStackElement_Hash.php b/includes/parser/PPDStackElement_Hash.php index 26351b21d3..5de5f479e9 100644 --- a/includes/parser/PPDStackElement_Hash.php +++ b/includes/parser/PPDStackElement_Hash.php @@ -59,6 +59,7 @@ class PPDStackElement_Hash extends PPDStackElement { } else { $accum[++$lastIndex] = '|'; } + // @phan-suppress-next-line PhanTypeMismatchForeach foreach ( $part->out as $node ) { if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) { $accum[$lastIndex] .= $node; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index d7a15aff23..130667e7d6 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -411,6 +411,7 @@ class Parser { */ public function __destruct() { if ( isset( $this->mLinkHolders ) ) { + // @phan-suppress-next-line PhanTypeObjectUnsetDeclaredProperty unset( $this->mLinkHolders ); } // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach diff --git a/includes/rcfeed/FormattedRCFeed.php b/includes/rcfeed/FormattedRCFeed.php index d0b7ae3220..9b5b29e208 100644 --- a/includes/rcfeed/FormattedRCFeed.php +++ b/includes/rcfeed/FormattedRCFeed.php @@ -61,6 +61,7 @@ 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/DerivativeResourceLoaderContext.php b/includes/resourceloader/DerivativeResourceLoaderContext.php index b11bd6fd33..cf0b3c275a 100644 --- a/includes/resourceloader/DerivativeResourceLoaderContext.php +++ b/includes/resourceloader/DerivativeResourceLoaderContext.php @@ -54,6 +54,7 @@ class DerivativeResourceLoaderContext extends ResourceLoaderContext { if ( $this->modules === self::INHERIT_VALUE ) { return $this->context->getModules(); } + // @phan-suppress-next-line PhanTypeMismatchReturn return $this->modules; } diff --git a/includes/resourceloader/ResourceLoaderOOUIImageModule.php b/includes/resourceloader/ResourceLoaderOOUIImageModule.php index 689ae58194..9c204fc711 100644 --- a/includes/resourceloader/ResourceLoaderOOUIImageModule.php +++ b/includes/resourceloader/ResourceLoaderOOUIImageModule.php @@ -98,7 +98,7 @@ class ResourceLoaderOOUIImageModule extends ResourceLoaderImageModule { if ( $module ) { $dataPath = $this->getThemeImagesPath( $theme, $module ); if ( !$dataPath ) { - return false; + return []; } } else { // Backwards-compatibility for things that probably shouldn't have used this class... diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 3893e92091..0954c45383 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -1133,7 +1133,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { * * There is light processing to simplify core maintenance. * @param array $definition - * @phan-param array $definition + * @phan-param array $definition */ protected function registerFiltersFromDefinitions( array $definition ) { $autoFillPriority = -1; diff --git a/includes/specialpage/LoginSignupSpecialPage.php b/includes/specialpage/LoginSignupSpecialPage.php index d609d2294d..62818a14d6 100644 --- a/includes/specialpage/LoginSignupSpecialPage.php +++ b/includes/specialpage/LoginSignupSpecialPage.php @@ -209,6 +209,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage { /** * @param string|null $subPage + * @suppress PhanTypeObjectUnsetDeclaredProperty */ public function execute( $subPage ) { if ( $this->mPosted ) { diff --git a/includes/specials/pagers/AllMessagesTablePager.php b/includes/specials/pagers/AllMessagesTablePager.php index 45d77cea01..bd27919819 100644 --- a/includes/specials/pagers/AllMessagesTablePager.php +++ b/includes/specials/pagers/AllMessagesTablePager.php @@ -354,7 +354,7 @@ class AllMessagesTablePager extends TablePager { } function getQueryInfo() { - return ''; + return []; } } diff --git a/includes/user/User.php b/includes/user/User.php index b0ee5cbb44..061c60f3bd 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -3602,6 +3602,7 @@ class User implements IDBAccessObject, UserIdentity { * * @param string $permissions,... Permissions to test * @return bool True if user is allowed to perform *any* of the given actions + * @suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, T191668#5263929 */ public function isAllowedAny() { return MediaWikiServices::getInstance() @@ -3614,6 +3615,7 @@ class User implements IDBAccessObject, UserIdentity { * ->getPermissionManager()->userHasAllRights(...) instead * @param string $permissions,... Permissions to test * @return bool True if the user is allowed to perform *all* of the given actions + * @suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, T191668#5263929 */ public function isAllowedAll() { return MediaWikiServices::getInstance() diff --git a/includes/utils/AvroValidator.php b/includes/utils/AvroValidator.php index 153b313599..b2d6077c26 100644 --- a/includes/utils/AvroValidator.php +++ b/includes/utils/AvroValidator.php @@ -124,6 +124,7 @@ class AvroValidator { $errors[] = $result; } if ( $errors ) { + // @phan-suppress-next-line PhanTypeMismatchReturn return [ "Expected any one of these to be true", $errors ]; } return "No schemas provided to union"; diff --git a/languages/Language.php b/languages/Language.php index dd5c63265f..ff66b25815 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -525,6 +525,7 @@ 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] ); diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 61a967dc46..d1a5720249 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -996,6 +996,7 @@ class LanguageConverter { */ private function reloadTables() { if ( $this->mTables ) { + // @phan-suppress-next-line PhanTypeObjectUnsetDeclaredProperty unset( $this->mTables ); } diff --git a/maintenance/includes/TextPassDumper.php b/maintenance/includes/TextPassDumper.php index 21b92c51c7..04767fa900 100644 --- a/maintenance/includes/TextPassDumper.php +++ b/maintenance/includes/TextPassDumper.php @@ -207,6 +207,7 @@ TEXT * This function resets $this->lb and closes all connections on it. * * @throws MWException + * @suppress PhanTypeObjectUnsetDeclaredProperty */ function rotateDb() { // Cleaning up old connections diff --git a/maintenance/mergeMessageFileList.php b/maintenance/mergeMessageFileList.php index 80e72fb8b4..48a66661da 100644 --- a/maintenance/mergeMessageFileList.php +++ b/maintenance/mergeMessageFileList.php @@ -157,6 +157,7 @@ class MergeMessageFileList extends Maintenance { require_once RUN_MAINTENANCE_IF_MAIN; $queue = []; +'@phan-var string[][] $mmfl'; foreach ( $mmfl['setupFiles'] as $fileName ) { if ( strval( $fileName ) === '' ) { continue; -- 2.20.1