From 4ef179e3359b79118285038fde2f78e425155fe1 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 21 Mar 2019 23:11:04 -0700 Subject: [PATCH] Fix/suppress misc phan errors (#5) Add lots of missing return statements, or remove incorrect doc blocks. Change-Id: I0881e98fbb9d0d4cf79ecc824064d24538055d3f --- .phan/config.php | 12 ++---------- includes/api/ApiBase.php | 1 + includes/auth/AuthenticationRequest.php | 1 + includes/block/Restriction/AbstractRestriction.php | 1 + includes/editpage/TextConflictHelper.php | 1 - .../filebackend/lockmanager/LockManagerGroup.php | 1 + includes/filerepo/file/File.php | 1 + includes/filerepo/file/ForeignDBFile.php | 1 + includes/installer/MssqlUpdater.php | 1 + includes/installer/PostgresUpdater.php | 7 ++++--- includes/installer/WebInstallerComplete.php | 1 + includes/installer/WebInstallerDocument.php | 1 + .../jobqueue/jobs/ClearWatchlistNotificationsJob.php | 1 + includes/libs/objectcache/MemcachedClient.php | 2 -- includes/libs/objectcache/MemcachedPeclBagOStuff.php | 3 +++ includes/libs/rdbms/database/IDatabase.php | 4 ---- includes/libs/rdbms/lbfactory/ILBFactory.php | 1 - includes/libs/rdbms/loadbalancer/ILoadBalancer.php | 1 - includes/page/ImagePage.php | 2 +- includes/profiler/ProfilerStub.php | 2 ++ includes/rcfeed/UDPRCFeedEngine.php | 1 + includes/resourceloader/ResourceLoader.php | 2 -- includes/search/NullIndexField.php | 1 + includes/specialpage/AuthManagerSpecialPage.php | 1 - includes/specialpage/ImageQueryPage.php | 1 + includes/specials/SpecialComparePages.php | 1 - includes/specials/SpecialEmailuser.php | 1 - includes/specials/SpecialExpandTemplates.php | 1 - includes/specials/SpecialMIMEsearch.php | 1 + includes/specials/SpecialPageLanguage.php | 1 + includes/specials/SpecialUndelete.php | 1 - includes/specials/forms/UploadForm.php | 2 +- includes/specials/pagers/NewFilesPager.php | 1 + maintenance/populatePPSortKey.php | 1 + maintenance/storage/recompressTracked.php | 4 +++- 35 files changed, 33 insertions(+), 32 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 2c0035ea04..4ddad1a433 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -119,8 +119,6 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ "PhanTypeExpectedObjectOrClassName", // approximate error count: 7 "PhanTypeExpectedObjectPropAccess", - // approximate error count: 3 - "PhanTypeInstantiateAbstract", // approximate error count: 62 "PhanTypeInvalidDimOffset", // approximate error count: 10 @@ -145,14 +143,8 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ "PhanTypeMismatchForeach", // approximate error count: 77 "PhanTypeMismatchProperty", - // approximate error count: 88 + // approximate error count: 85 "PhanTypeMismatchReturn", - // approximate error count: 43 - "PhanTypeMissingReturn", - // approximate error count: 1 - "PhanTypeNoAccessiblePropertiesForeach", - // approximate error count: 4 - "PhanTypeNonVarPassByRef", // approximate error count: 12 "PhanTypeObjectUnsetDeclaredProperty", // approximate error count: 9 @@ -163,7 +155,7 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ "PhanUndeclaredConstant", // approximate error count: 3 "PhanUndeclaredInvokeInCallable", - // approximate error count: 242 + // approximate error count: 239 "PhanUndeclaredMethod", // approximate error count: 847 "PhanUndeclaredProperty", diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 9b3d11664d..528ced81f6 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -800,6 +800,7 @@ abstract class ApiBase extends ContextSource { // $results if all are done. unset( $targets[$placeholder] ); $placeholder = '{' . $placeholder . '}'; + // @phan-suppress-next-line PhanTypeNoAccessiblePropertiesForeach foreach ( $results[$target] as $value ) { if ( !preg_match( '/^[^{}]*$/', $value ) ) { // Skip values that make invalid parameter names. diff --git a/includes/auth/AuthenticationRequest.php b/includes/auth/AuthenticationRequest.php index 7fc362a204..4744c4d4b9 100644 --- a/includes/auth/AuthenticationRequest.php +++ b/includes/auth/AuthenticationRequest.php @@ -370,6 +370,7 @@ abstract class AuthenticationRequest { * @return AuthenticationRequest */ public static function __set_state( $data ) { + // @phan-suppress-next-line PhanTypeInstantiateAbstract $ret = new static(); foreach ( $data as $k => $v ) { $ret->$k = $v; diff --git a/includes/block/Restriction/AbstractRestriction.php b/includes/block/Restriction/AbstractRestriction.php index 20678ad0c1..7970266976 100644 --- a/includes/block/Restriction/AbstractRestriction.php +++ b/includes/block/Restriction/AbstractRestriction.php @@ -97,6 +97,7 @@ abstract class AbstractRestriction implements Restriction { * @inheritDoc */ public static function newFromRow( \stdClass $row ) { + // @phan-suppress-next-line PhanTypeInstantiateAbstract return new static( $row->ir_ipb_id, $row->ir_value ); } diff --git a/includes/editpage/TextConflictHelper.php b/includes/editpage/TextConflictHelper.php index f7d0945ec4..2471b526a0 100644 --- a/includes/editpage/TextConflictHelper.php +++ b/includes/editpage/TextConflictHelper.php @@ -166,7 +166,6 @@ class TextConflictHelper { * HTML to build the textbox1 on edit conflicts * * @param array $customAttribs - * @return string HTML */ public function getEditConflictMainTextBox( array $customAttribs = [] ) { $builder = new TextboxBuilder(); diff --git a/includes/filebackend/lockmanager/LockManagerGroup.php b/includes/filebackend/lockmanager/LockManagerGroup.php index aa955d055c..43f6010d3c 100644 --- a/includes/filebackend/lockmanager/LockManagerGroup.php +++ b/includes/filebackend/lockmanager/LockManagerGroup.php @@ -129,6 +129,7 @@ class LockManagerGroup { } $config['logger'] = LoggerFactory::getInstance( 'LockManager' ); + // @phan-suppress-next-line PhanTypeInstantiateAbstract $this->managers[$name]['instance'] = new $class( $config ); } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 97abe33dae..7d4f4dfe85 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -29,6 +29,7 @@ use MediaWiki\MediaWikiServices; * @ingroup FileAbstraction */ +// @phan-file-suppress PhanTypeMissingReturn false positives /** * Implements some public methods and some protected utility functions which * are required by multiple child classes. Contains stub functionality for diff --git a/includes/filerepo/file/ForeignDBFile.php b/includes/filerepo/file/ForeignDBFile.php index 1869967fc3..3438a6388b 100644 --- a/includes/filerepo/file/ForeignDBFile.php +++ b/includes/filerepo/file/ForeignDBFile.php @@ -24,6 +24,7 @@ use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\DBUnexpectedError; +// @phan-file-suppress PhanTypeMissingReturn false positives /** * Foreign file with an accessible MediaWiki database * diff --git a/includes/installer/MssqlUpdater.php b/includes/installer/MssqlUpdater.php index 75f389478c..b8dc5ff451 100644 --- a/includes/installer/MssqlUpdater.php +++ b/includes/installer/MssqlUpdater.php @@ -166,6 +166,7 @@ class MssqlUpdater extends DatabaseUpdater { parent::applyPatch( $path, $isFullPath, $msg ); $this->db->scrollableCursor( $prevScroll ); $this->db->prepareStatements( $prevPrep ); + return true; } /** diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index 9ba8d027e4..008240a38c 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -839,7 +839,7 @@ END; if ( !$this->db->tableExists( $table, __METHOD__ ) ) { $this->output( "...skipping: '$table' table doesn't exist yet.\n" ); - return; + return true; } // Second requirement: the new index must be missing @@ -853,17 +853,18 @@ END; " $old should be manually removed if not needed anymore.\n" ); } - return; + return true; } // Third requirement: the old index must exist if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) { $this->output( "...skipping: index $old doesn't exist.\n" ); - return; + return true; } $this->db->query( "ALTER INDEX $old RENAME TO $new" ); + return true; } protected function dropPgField( $table, $field ) { diff --git a/includes/installer/WebInstallerComplete.php b/includes/installer/WebInstallerComplete.php index 456058e455..9f804891cb 100644 --- a/includes/installer/WebInstallerComplete.php +++ b/includes/installer/WebInstallerComplete.php @@ -59,6 +59,7 @@ class WebInstallerComplete extends WebInstallerPage { $this->parent->restoreLinkPopups(); $this->endForm( false, false ); + return ''; } } diff --git a/includes/installer/WebInstallerDocument.php b/includes/installer/WebInstallerDocument.php index f79d272153..5241b3c524 100644 --- a/includes/installer/WebInstallerDocument.php +++ b/includes/installer/WebInstallerDocument.php @@ -32,6 +32,7 @@ abstract class WebInstallerDocument extends WebInstallerPage { $this->parent->output->addWikiTextAsInterface( $text ); $this->startForm(); $this->endForm( false ); + return ''; } /** diff --git a/includes/jobqueue/jobs/ClearWatchlistNotificationsJob.php b/includes/jobqueue/jobs/ClearWatchlistNotificationsJob.php index b71580a525..3b2c899012 100644 --- a/includes/jobqueue/jobs/ClearWatchlistNotificationsJob.php +++ b/includes/jobqueue/jobs/ClearWatchlistNotificationsJob.php @@ -96,5 +96,6 @@ class ClearWatchlistNotificationsJob extends Job { $firstBatch = false; } } while ( $idsToUpdate ); + return true; } } diff --git a/includes/libs/objectcache/MemcachedClient.php b/includes/libs/objectcache/MemcachedClient.php index 1cc07b71ef..937ca5546d 100644 --- a/includes/libs/objectcache/MemcachedClient.php +++ b/includes/libs/objectcache/MemcachedClient.php @@ -255,8 +255,6 @@ class MemcachedClient { * Memcache initializer * * @param array $args Associative array of settings - * - * @return mixed */ public function __construct( $args ) { $this->set_servers( $args['servers'] ?? array() ); diff --git a/includes/libs/objectcache/MemcachedPeclBagOStuff.php b/includes/libs/objectcache/MemcachedPeclBagOStuff.php index 489f00102e..692771dcfb 100644 --- a/includes/libs/objectcache/MemcachedPeclBagOStuff.php +++ b/includes/libs/objectcache/MemcachedPeclBagOStuff.php @@ -138,6 +138,9 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { return $params; } + /** + * @suppress PhanTypeNonVarPassByRef + */ protected function doGet( $key, $flags = 0, &$casToken = null ) { $this->debugLog( "get($key)" ); if ( defined( Memcached::class . '::GET_EXTENDED' ) ) { // v3.0.0 diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php index b4440d6dfa..90b888d6a4 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -1554,7 +1554,6 @@ interface IDatabase { * * @param callable $callback * @param string $fname Caller name - * @return mixed * @since 1.28 */ public function onTransactionResolution( callable $callback, $fname = __METHOD__ ); @@ -1598,7 +1597,6 @@ interface IDatabase { * * @param callable $callback * @param string $fname - * @return mixed * @since 1.20 * @deprecated Since 1.32 */ @@ -1644,7 +1642,6 @@ interface IDatabase { * * @param string $name Callback name * @param callable|null $callback Use null to unset a listener - * @return mixed * @since 1.28 */ public function setTransactionListener( $name, callable $callback = null ); @@ -2172,7 +2169,6 @@ interface IDatabase { * the aliases can be removed, and then the old X-named indexes dropped. * * @param string[] $aliases - * @return mixed * @since 1.31 */ public function setIndexAliases( array $aliases ); diff --git a/includes/libs/rdbms/lbfactory/ILBFactory.php b/includes/libs/rdbms/lbfactory/ILBFactory.php index 98c06adf80..cb8be212b8 100644 --- a/includes/libs/rdbms/lbfactory/ILBFactory.php +++ b/includes/libs/rdbms/lbfactory/ILBFactory.php @@ -390,7 +390,6 @@ interface ILBFactory { * the aliases can be removed, and then the old X-named indexes dropped. * * @param string[] $aliases - * @return mixed * @since 1.31 */ public function setIndexAliases( array $aliases ); diff --git a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php index b20bf04e45..6b8d14612f 100644 --- a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php @@ -680,7 +680,6 @@ interface ILoadBalancer { * the aliases can be removed, and then the old X-named indexes dropped. * * @param string[] $aliases - * @return mixed * @since 1.31 */ public function setIndexAliases( array $aliases ); diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index 60237ff1ab..6c1ac39bb2 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -1222,7 +1222,7 @@ EOT * @return TitleArray|Title[] */ public function getForeignCategories() { - $this->mPage->getForeignCategories(); + return $this->mPage->getForeignCategories(); } } diff --git a/includes/profiler/ProfilerStub.php b/includes/profiler/ProfilerStub.php index 1017e44660..fe46798607 100644 --- a/includes/profiler/ProfilerStub.php +++ b/includes/profiler/ProfilerStub.php @@ -32,9 +32,11 @@ class ProfilerStub extends Profiler { } public function getFunctionStats() { + return []; } public function getOutput() { + return ''; } public function close() { diff --git a/includes/rcfeed/UDPRCFeedEngine.php b/includes/rcfeed/UDPRCFeedEngine.php index f76d771ef4..7e69a02572 100644 --- a/includes/rcfeed/UDPRCFeedEngine.php +++ b/includes/rcfeed/UDPRCFeedEngine.php @@ -32,5 +32,6 @@ class UDPRCFeedEngine extends RCFeedEngine { public function send( array $feed, $line ) { $transport = UDPTransport::newFromString( $feed['uri'] ); $transport->emit( $line ); + return true; } } diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 839948dbc6..4cf87350dd 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -319,8 +319,6 @@ class ResourceLoader implements LoggerAwareInterface { * @throws MWException If a duplicate module registration is attempted * @throws MWException If a module name contains illegal characters (pipes or commas) * @throws MWException If something other than a ResourceLoaderModule is being registered - * @return bool False if there were any errors, in which case one or more modules were - * not registered */ public function register( $name, $info = null ) { $moduleSkinStyles = $this->config->get( 'ResourceModuleSkinStyles' ); diff --git a/includes/search/NullIndexField.php b/includes/search/NullIndexField.php index ff1e8cbf74..22f59987c5 100644 --- a/includes/search/NullIndexField.php +++ b/includes/search/NullIndexField.php @@ -22,6 +22,7 @@ class NullIndexField implements SearchIndexField { * @return $this */ public function setFlag( $flag, $unset = false ) { + return $this; } /** diff --git a/includes/specialpage/AuthManagerSpecialPage.php b/includes/specialpage/AuthManagerSpecialPage.php index 0e0a26af3a..101570fe89 100644 --- a/includes/specialpage/AuthManagerSpecialPage.php +++ b/includes/specialpage/AuthManagerSpecialPage.php @@ -710,7 +710,6 @@ abstract class AuthManagerSpecialPage extends SpecialPage { * are shown closer to the bottom; weight defaults to 0. Negative weight is allowed.) * Keep order if weights are equal. * @param array &$formDescriptor - * @return array */ protected static function sortFormDescriptorFields( array &$formDescriptor ) { $i = 0; diff --git a/includes/specialpage/ImageQueryPage.php b/includes/specialpage/ImageQueryPage.php index 8df64937e5..722251d3dd 100644 --- a/includes/specialpage/ImageQueryPage.php +++ b/includes/specialpage/ImageQueryPage.php @@ -68,6 +68,7 @@ abstract class ImageQueryPage extends QueryPage { // Gotta override this since it's abstract function formatResult( $skin, $result ) { + return false; } /** diff --git a/includes/specials/SpecialComparePages.php b/includes/specials/SpecialComparePages.php index 9d1b79e74b..36928cae78 100644 --- a/includes/specials/SpecialComparePages.php +++ b/includes/specials/SpecialComparePages.php @@ -44,7 +44,6 @@ class SpecialComparePages extends SpecialPage { * Show a form for filtering namespace and username * * @param string|null $par - * @return string */ public function execute( $par ) { $this->setHeaders(); diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 887f90541d..ded0891d30 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -298,7 +298,6 @@ class SpecialEmailUser extends UnlistedSpecialPage { * Form to ask for target user name. * * @param string $name User name submitted. - * @return string Form asking for user name. */ protected function userForm( $name ) { $htmlForm = HTMLForm::factory( 'ooui', [ diff --git a/includes/specials/SpecialExpandTemplates.php b/includes/specials/SpecialExpandTemplates.php index 619665bdb4..9ea5e089a6 100644 --- a/includes/specials/SpecialExpandTemplates.php +++ b/includes/specials/SpecialExpandTemplates.php @@ -154,7 +154,6 @@ class SpecialExpandTemplates extends SpecialPage { * * @param string $title Value for context title field * @param string $input Value for input textbox - * @return string */ private function makeForm( $title, $input ) { $fields = [ diff --git a/includes/specials/SpecialMIMEsearch.php b/includes/specials/SpecialMIMEsearch.php index 2599b16300..e8e5ea0d06 100644 --- a/includes/specials/SpecialMIMEsearch.php +++ b/includes/specials/SpecialMIMEsearch.php @@ -132,6 +132,7 @@ class MIMEsearchPage extends QueryPage { ->setMethod( 'get' ) ->prepareForm() ->displayForm( false ); + return ''; } protected function getSuggestionsForTypes() { diff --git a/includes/specials/SpecialPageLanguage.php b/includes/specials/SpecialPageLanguage.php index 52db060122..7e41305bb1 100644 --- a/includes/specials/SpecialPageLanguage.php +++ b/includes/specials/SpecialPageLanguage.php @@ -44,6 +44,7 @@ class SpecialPageLanguage extends FormSpecialPage { protected function preText() { $this->getOutput()->addModules( 'mediawiki.special.pageLanguage' ); + return parent::preText(); } protected function getFormFields() { diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index 51d6fd9b45..5f694267ff 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -549,7 +549,6 @@ class SpecialUndelete extends SpecialPage { * * @param Revision $previousRev * @param Revision $currentRev - * @return string HTML */ function showDiff( $previousRev, $currentRev ) { $diffContext = clone $this->getContext(); diff --git a/includes/specials/forms/UploadForm.php b/includes/specials/forms/UploadForm.php index da4398ad9f..7a47edffd5 100644 --- a/includes/specials/forms/UploadForm.php +++ b/includes/specials/forms/UploadForm.php @@ -393,7 +393,7 @@ class UploadForm extends HTMLForm { */ public function show() { $this->addUploadJS(); - parent::show(); + return parent::show(); } /** diff --git a/includes/specials/pagers/NewFilesPager.php b/includes/specials/pagers/NewFilesPager.php index d05ebf83af..88dff6e02f 100644 --- a/includes/specials/pagers/NewFilesPager.php +++ b/includes/specials/pagers/NewFilesPager.php @@ -204,5 +204,6 @@ class NewFilesPager extends RangeChronologicalPager { . htmlspecialchars( $time ) . "
\n" ); + return ''; } } diff --git a/maintenance/populatePPSortKey.php b/maintenance/populatePPSortKey.php index 1ba70549a4..591fbd4b39 100644 --- a/maintenance/populatePPSortKey.php +++ b/maintenance/populatePPSortKey.php @@ -93,6 +93,7 @@ class PopulatePPSortKey extends LoggedUpdateMaintenance { } $this->output( "Populating page_props.pp_sortkey complete.\n" ); + return true; } protected function getUpdateKey() { diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 7f3644288b..7f89ce9e6e 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -274,7 +274,9 @@ class RecompressTracked { function dispatch( /*...*/ ) { $args = func_get_args(); $pipes = $this->replicaPipes; - $numPipes = stream_select( $x = [], $pipes, $y = [], 3600 ); + $x = []; + $y = []; + $numPipes = stream_select( $x, $pipes, $y, 3600 ); if ( !$numPipes ) { $this->critical( "Error waiting to write to replica DBs. Aborting" ); exit( 1 ); -- 2.20.1