From 7f7efbe026b01be36019c26571224a6e8a178677 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Thu, 29 Aug 2019 11:59:59 +0200 Subject: [PATCH] Globally unsuppress phan issues with low count All of these suppression prevent the detection of many common mistakes, and could easily prevent things like T231488. Especially if there are few issues of a given type, it's way better to suppress them inline, instead of disabling them for the whole core. This patch only touches the one with a lower count (although those counts may be out of date). Bug: T231636 Change-Id: Ica50297ec7c71a81ba2204f9763499da925067bd --- .phan/config.php | 26 +- .phan/internal_stubs/intl.phan_php | 1791 +++++++++++++++++ includes/api/ApiMessageTrait.php | 1 + includes/content/ContentHandler.php | 6 +- .../fields/HTMLAutoCompleteSelectField.php | 2 + includes/installer/DatabaseUpdater.php | 1 + includes/libs/ExplodeIterator.php | 4 +- includes/libs/GenericArrayObject.php | 1 + includes/libs/MWMessagePack.php | 1 + .../libs/filebackend/SwiftFileBackend.php | 2 + includes/libs/mime/MSCompoundFileReader.php | 2 + includes/libs/rdbms/database/Database.php | 4 +- .../database/resultwrapper/IResultWrapper.php | 1 + includes/media/GIFMetadataExtractor.php | 1 + includes/media/WebPHandler.php | 1 + includes/parser/LinkHolderArray.php | 1 + includes/parser/Parser.php | 1 + .../ResourceLoaderOOUIImageModule.php | 1 + includes/revisionlist/RevisionListBase.php | 1 + includes/session/SessionManager.php | 1 + .../specialpage/AuthManagerSpecialPage.php | 5 +- includes/utils/ZipDirectoryReader.php | 1 + languages/Language.php | 1 + .../convertExtensionToRegistration.php | 1 + 24 files changed, 1828 insertions(+), 29 deletions(-) create mode 100644 .phan/internal_stubs/intl.phan_php diff --git a/.phan/config.php b/.phan/config.php index 8746ada384..5813b29468 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -82,18 +82,12 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ "PhanCommentParamOnEmptyParamList", // approximate error count: 29 "PhanCommentParamWithoutRealParam", - // approximate error count: 2 - "PhanCompatibleNegativeStringOffset", // approximate error count: 21 "PhanParamReqAfterOpt", // approximate error count: 26 "PhanParamSignatureMismatch", - // approximate error count: 4 - "PhanParamSignatureMismatchInternal", // approximate error count: 127 "PhanParamTooMany", - // approximate error count: 2 - "PhanTraitParentReference", // approximate error count: 30 "PhanTypeArraySuspicious", // approximate error count: 27 @@ -102,16 +96,10 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ "PhanTypeComparisonFromArray", // approximate error count: 63 "PhanTypeInvalidDimOffset", - // approximate error count: 7 - "PhanTypeInvalidLeftOperandOfIntegerOp", - // approximate error count: 2 - "PhanTypeInvalidRightOperandOfIntegerOp", // approximate error count: 154 "PhanTypeMismatchArgument", // approximate error count: 27 "PhanTypeMismatchArgumentInternal", - // approximate error count: 2 - "PhanTypeMismatchDimEmpty", // approximate error count: 27 "PhanTypeMismatchDimFetch", // approximate error count: 10 @@ -122,25 +110,21 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ "PhanTypeMismatchReturn", // approximate error count: 12 "PhanTypeObjectUnsetDeclaredProperty", - // approximate error count: 9 - "PhanTypeSuspiciousNonTraversableForeach", - // approximate error count: 3 - "PhanTypeSuspiciousStringExpression", // approximate error count: 22 "PhanUndeclaredConstant", - // approximate error count: 3 - "PhanUndeclaredInvokeInCallable", // approximate error count: 237 "PhanUndeclaredMethod", // approximate error count: 846 "PhanUndeclaredProperty", - // approximate error count: 2 - "PhanUndeclaredVariableAssignOp", // approximate error count: 55 "PhanUndeclaredVariableDim", ] ); $cfg['ignore_undeclared_variables_in_global_scope'] = true; -$cfg['globals_type_map']['IP'] = 'string'; +$cfg['globals_type_map'] = array_merge( $cfg['globals_type_map'], [ + 'IP' => 'string', + 'wgGalleryOptions' => 'array', + 'wgDummyLanguageCodes' => 'string[]', +] ); return $cfg; diff --git a/.phan/internal_stubs/intl.phan_php b/.phan/internal_stubs/intl.phan_php new file mode 100644 index 0000000000..cffb0050ad --- /dev/null +++ b/.phan/internal_stubs/intl.phan_php @@ -0,0 +1,1791 @@ +getHTML() . "
\n"; + // @phan-suppress-next-line PhanTypeMismatchDimEmpty $this->mClass[] = 'mw-htmlform-hide-if'; } @@ -178,6 +179,7 @@ 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/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index de7a347120..8a9cd05871 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -419,6 +419,7 @@ abstract class DatabaseUpdater { foreach ( $updates as $funcList ) { list( $func, $args, $origParams ) = $funcList; + // @phan-suppress-next-line PhanUndeclaredInvokeInCallable $func( ...$args ); flush(); $this->updatesSkipped[] = $origParams; diff --git a/includes/libs/ExplodeIterator.php b/includes/libs/ExplodeIterator.php index d4abdc86e8..7d2c5d62c8 100644 --- a/includes/libs/ExplodeIterator.php +++ b/includes/libs/ExplodeIterator.php @@ -89,7 +89,7 @@ class ExplodeIterator implements Iterator { } /** - * @return string + * @return void */ public function next() { if ( $this->endPos === false ) { @@ -103,8 +103,6 @@ class ExplodeIterator implements Iterator { } } $this->refreshCurrent(); - - return $this->current; } /** diff --git a/includes/libs/GenericArrayObject.php b/includes/libs/GenericArrayObject.php index a9b26ac913..2e0a2afe8c 100644 --- a/includes/libs/GenericArrayObject.php +++ b/includes/libs/GenericArrayObject.php @@ -211,6 +211,7 @@ abstract class GenericArrayObject extends ArrayObject { * @param string $serialization * * @return array + * @suppress PhanParamSignatureMismatchInternal The stub appears to be wrong */ public function unserialize( $serialization ) { $serializationData = unserialize( $serialization ); diff --git a/includes/libs/MWMessagePack.php b/includes/libs/MWMessagePack.php index 107672e361..cb9e647f49 100644 --- a/includes/libs/MWMessagePack.php +++ b/includes/libs/MWMessagePack.php @@ -134,6 +134,7 @@ class MWMessagePack { // int64 // pack() does not support 64-bit ints either so pack into two 32-bits $p1 = pack( 'l', $value & 0xFFFFFFFF ); + // @phan-suppress-next-line PhanTypeInvalidLeftOperandOfIntegerOp $p2 = pack( 'l', ( $value >> 32 ) & 0xFFFFFFFF ); return self::$bigendian ? pack( 'Ca4a4', 0xD3, $p1, $p2 ) diff --git a/includes/libs/filebackend/SwiftFileBackend.php b/includes/libs/filebackend/SwiftFileBackend.php index e576c6429e..1e9c7c595a 100644 --- a/includes/libs/filebackend/SwiftFileBackend.php +++ b/includes/libs/filebackend/SwiftFileBackend.php @@ -884,6 +884,7 @@ class SwiftFileBackend extends FileBackendStore { throw new FileBackendError( "Iterator page I/O error." ); } $objects = $status->value; + // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach foreach ( $objects as $object ) { // files and directories if ( substr( $object, -1 ) === '/' ) { $dirs[] = $object; // directories end in '/' @@ -905,6 +906,7 @@ class SwiftFileBackend extends FileBackendStore { $objects = $status->value; + // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach foreach ( $objects as $object ) { // files $objectDir = $getParentDir( $object ); // directory of object diff --git a/includes/libs/mime/MSCompoundFileReader.php b/includes/libs/mime/MSCompoundFileReader.php index 0383def62c..26e9685166 100644 --- a/includes/libs/mime/MSCompoundFileReader.php +++ b/includes/libs/mime/MSCompoundFileReader.php @@ -149,6 +149,7 @@ class MSCompoundFileReader { $this->error( 'invalid signature: ' . bin2hex( $this->header['header_signature'] ), self::ERROR_INVALID_SIGNATURE ); } + // @phan-suppress-next-line PhanTypeInvalidRightOperandOfIntegerOp $this->sectorLength = 1 << $this->header['sector_shift']; $this->readDifat(); $this->readDirectory(); @@ -220,6 +221,7 @@ class MSCompoundFileReader { } private function readSector( $sectorId ) { + // @phan-suppress-next-line PhanTypeInvalidRightOperandOfIntegerOp return $this->readOffset( $this->sectorOffset( $sectorId ), 1 << $this->header['sector_shift'] ); } diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 084500ac8e..b5ec6521a5 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -3522,7 +3522,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware if ( in_array( $entry[2], $sectionIds, true ) ) { $callback = $entry[0]; $this->trxEndCallbacks[$key][0] = function () use ( $callback ) { - // @phan-suppress-next-line PhanInfiniteRecursion No recursion at all here, phan is confused + // @phan-suppress-next-line PhanInfiniteRecursion, PhanUndeclaredInvokeInCallable return $callback( self::TRIGGER_ROLLBACK, $this ); }; // This "on resolution" callback no longer belongs to a section. @@ -3647,6 +3647,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware try { ++$count; list( $phpCallback ) = $callback; + // @phan-suppress-next-line PhanUndeclaredInvokeInCallable $phpCallback( $this ); } catch ( Exception $ex ) { ( $this->errorLogger )( $ex ); @@ -3682,6 +3683,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware foreach ( $callbacks as $entry ) { if ( $sectionIds === null || in_array( $entry[2], $sectionIds, true ) ) { try { + // @phan-suppress-next-line PhanUndeclaredInvokeInCallable $entry[0]( $trigger, $this ); } catch ( Exception $ex ) { ( $this->errorLogger )( $ex ); diff --git a/includes/libs/rdbms/database/resultwrapper/IResultWrapper.php b/includes/libs/rdbms/database/resultwrapper/IResultWrapper.php index 616fed9d13..955725165b 100644 --- a/includes/libs/rdbms/database/resultwrapper/IResultWrapper.php +++ b/includes/libs/rdbms/database/resultwrapper/IResultWrapper.php @@ -76,6 +76,7 @@ interface IResultWrapper extends Iterator { /** * @return stdClass + * @suppress PhanParamSignatureMismatchInternal */ function next(); } diff --git a/includes/media/GIFMetadataExtractor.php b/includes/media/GIFMetadataExtractor.php index 591ccf191f..4e5c4ea924 100644 --- a/includes/media/GIFMetadataExtractor.php +++ b/includes/media/GIFMetadataExtractor.php @@ -282,6 +282,7 @@ class GIFMetadataExtractor { } $buf = unpack( 'C', $data )[1]; $bpp = ( $buf & 7 ) + 1; + // @phan-suppress-next-line PhanTypeInvalidLeftOperandOfIntegerOp $buf >>= 7; $have_map = $buf & 1; diff --git a/includes/media/WebPHandler.php b/includes/media/WebPHandler.php index 295a9785b5..854c24949c 100644 --- a/includes/media/WebPHandler.php +++ b/includes/media/WebPHandler.php @@ -182,6 +182,7 @@ class WebPHandler extends BitmapHandler { * Decodes a lossless chunk header * @param string $header First few bytes of the header, expected to be at least 13 bytes long * @return bool|array See WebPHandler::decodeHeader + * @suppress PhanTypeInvalidLeftOperandOfIntegerOp */ public static function decodeLosslessChunkHeader( $header ) { // Bytes 0-3 are 'VP8L' diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 64164490c2..5eb799e9e6 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -48,6 +48,7 @@ class LinkHolderArray { * Reduce memory usage to reduce the impact of circular references */ public function __destruct() { + // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach foreach ( $this as $name => $value ) { unset( $this->$name ); } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index a19f86ca67..d7a15aff23 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -413,6 +413,7 @@ class Parser { if ( isset( $this->mLinkHolders ) ) { unset( $this->mLinkHolders ); } + // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach foreach ( $this as $name => $value ) { unset( $this->$name ); } diff --git a/includes/resourceloader/ResourceLoaderOOUIImageModule.php b/includes/resourceloader/ResourceLoaderOOUIImageModule.php index c6d4cdfde3..689ae58194 100644 --- a/includes/resourceloader/ResourceLoaderOOUIImageModule.php +++ b/includes/resourceloader/ResourceLoaderOOUIImageModule.php @@ -137,6 +137,7 @@ class ResourceLoaderOOUIImageModule extends ResourceLoaderImageModule { $dataPath->getRemoteBasePath() ); } else { + // @phan-suppress-next-line PhanTypeSuspiciousStringExpression $path = dirname( $dataPath ) . '/' . $path; } }; diff --git a/includes/revisionlist/RevisionListBase.php b/includes/revisionlist/RevisionListBase.php index fb379c953a..db134468fb 100644 --- a/includes/revisionlist/RevisionListBase.php +++ b/includes/revisionlist/RevisionListBase.php @@ -107,6 +107,7 @@ abstract class RevisionListBase extends ContextSource implements Iterator { /** * Move the iteration pointer to the next list item, and return it. * @return Revision + * @suppress PhanParamSignatureMismatchInternal */ public function next() { $this->res->next(); diff --git a/includes/session/SessionManager.php b/includes/session/SessionManager.php index c635b97141..85f4569e81 100644 --- a/includes/session/SessionManager.php +++ b/includes/session/SessionManager.php @@ -410,6 +410,7 @@ final class SessionManager implements SessionManagerInterface { $provider->setConfig( $this->config ); $provider->setManager( $this ); if ( isset( $this->sessionProviders[(string)$provider] ) ) { + // @phan-suppress-next-line PhanTypeSuspiciousStringExpression throw new \UnexpectedValueException( "Duplicate provider name \"$provider\"" ); } $this->sessionProviders[(string)$provider] = $provider; diff --git a/includes/specialpage/AuthManagerSpecialPage.php b/includes/specialpage/AuthManagerSpecialPage.php index ba7785cc4b..e1f0588de5 100644 --- a/includes/specialpage/AuthManagerSpecialPage.php +++ b/includes/specialpage/AuthManagerSpecialPage.php @@ -435,10 +435,11 @@ abstract class AuthManagerSpecialPage extends SpecialPage { if ( is_string( reset( $status ) ) ) { $status = Status::newFatal( ...$status ); } elseif ( is_array( reset( $status ) ) ) { - $status = Status::newGood(); + $ret = Status::newGood(); foreach ( $status as $message ) { - $status->fatal( ...$message ); + $ret->fatal( ...$message ); } + $status = $ret; } else { throw new UnexpectedValueException( 'invalid HTMLForm::trySubmit() return value: ' . 'first element of array is ' . gettype( reset( $status ) ) ); diff --git a/includes/utils/ZipDirectoryReader.php b/includes/utils/ZipDirectoryReader.php index e7846f43e2..4207d4104c 100644 --- a/includes/utils/ZipDirectoryReader.php +++ b/includes/utils/ZipDirectoryReader.php @@ -369,6 +369,7 @@ class ZipDirectoryReader { * Read the central directory at the given location * @param int $offset * @param int $size + * @suppress PhanTypeInvalidLeftOperandOfIntegerOp */ function readCentralDirectory( $offset, $size ) { $block = $this->getBlock( $offset, $size ); diff --git a/languages/Language.php b/languages/Language.php index bb256c9c99..dd5c63265f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -467,6 +467,7 @@ class Language { /** * Reduce memory usage + * @suppress PhanTypeSuspiciousNonTraversableForeach */ function __destruct() { foreach ( $this as $name => $value ) { diff --git a/maintenance/convertExtensionToRegistration.php b/maintenance/convertExtensionToRegistration.php index a09ca5ceb5..3db0511eae 100644 --- a/maintenance/convertExtensionToRegistration.php +++ b/maintenance/convertExtensionToRegistration.php @@ -171,6 +171,7 @@ class ConvertExtensionToRegistration extends Maintenance { } // check if $func exists in the global scope if ( function_exists( $func ) ) { + // @phan-suppress-next-next-line PhanTypeSuspiciousStringExpression $this->fatalError( "Error: Global functions cannot be converted to JSON. " . "Please move your extension function ($func) into a class." ); -- 2.20.1