From 268346e5628ff648c6764c46b534049efffe7790 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Tue, 18 Jun 2019 22:26:00 +0200 Subject: [PATCH] phan: Enable PhanTypeMismatchArgument issue Bug: T231636 Depends-On: I5de4f8f32a47c3f41c990ffe2ebd091fc23d1a58 Change-Id: I34d65fe3ff1916f2af675f0b1f19641b0cdfadc0 --- .phan/config.php | 3 --- includes/EditPage.php | 2 +- includes/MovePage.php | 2 +- includes/api/ApiBase.php | 5 +++++ includes/api/ApiErrorFormatter.php | 1 + includes/api/ApiQueryLogEvents.php | 1 + includes/api/ApiTag.php | 2 ++ includes/api/ApiUpload.php | 1 + includes/block/BlockManager.php | 2 ++ includes/filerepo/file/ArchivedFile.php | 2 ++ includes/http/HttpRequestFactory.php | 2 +- includes/mail/UserMailer.php | 1 + includes/page/MovePageFactory.php | 3 +-- includes/parser/PPDPart_Hash.php | 1 + includes/site/SiteImporter.php | 2 ++ includes/skins/BaseTemplate.php | 1 + maintenance/refreshFileHeaders.php | 4 ++++ 17 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 56a8ccb0a6..0fdefe054d 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -101,9 +101,6 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [ //after dropping HHVM // approximate error count: 110 "PhanParamTooMany", // False positives with variargs. Unsuppress after dropping HHVM - - // approximate error count: 45 - "PhanTypeMismatchArgument", ] ); // This helps a lot in discovering bad code, but unfortunately it will always fail for diff --git a/includes/EditPage.php b/includes/EditPage.php index 10eea89001..9182300fcf 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1156,7 +1156,7 @@ class EditPage { $out->showErrorPage( 'modeleditnotsupported-title', 'modeleditnotsupported-text', - $modelName + [ $modelName ] ); return false; } diff --git a/includes/MovePage.php b/includes/MovePage.php index 634e7affe2..59baae78e2 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -83,7 +83,7 @@ class MovePage { * @param ServiceOptions|null $options * @param ILoadBalancer|null $loadBalancer * @param NamespaceInfo|null $nsInfo - * @param WatchedItemStore|null $watchedItems + * @param WatchedItemStoreInterface|null $watchedItems * @param PermissionManager|null $permMgr */ public function __construct( diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 056d10c3c9..7518008f9d 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1585,6 +1585,7 @@ abstract class ApiBase extends ContextSource { 'integeroutofrange', [ 'min' => $min, 'max' => $max, 'botMax' => $botMax ?: $max ] ); + // @phan-suppress-next-line PhanTypeMismatchArgument $this->warnOrDie( $msg, $enforceLimits ); $value = $min; } @@ -1606,6 +1607,7 @@ abstract class ApiBase extends ContextSource { 'integeroutofrange', [ 'min' => $min, 'max' => $max, 'botMax' => $botMax ?: $max ] ); + // @phan-suppress-next-line PhanTypeMismatchArgument $this->warnOrDie( $msg, $enforceLimits ); $value = $botMax; } @@ -1616,6 +1618,7 @@ abstract class ApiBase extends ContextSource { 'integeroutofrange', [ 'min' => $min, 'max' => $max, 'botMax' => $botMax ?: $max ] ); + // @phan-suppress-next-line PhanTypeMismatchArgument $this->warnOrDie( $msg, $enforceLimits ); $value = $max; } @@ -2022,6 +2025,7 @@ abstract class ApiBase extends ContextSource { */ public function dieWithException( $exception, array $options = [] ) { $this->dieWithError( + // @phan-suppress-next-line PhanTypeMismatchArgument $this->getErrorFormatter()->getMessageFromException( $exception, $options ) ); } @@ -2464,6 +2468,7 @@ abstract class ApiBase extends ContextSource { if ( $m ) { $m = new ApiHelpParamValueMessage( $value, + // @phan-suppress-next-line PhanTypeMismatchArgument [ $m->getKey(), 'api-help-param-no-description' ], $m->getParams(), isset( $deprecatedValues[$value] ) diff --git a/includes/api/ApiErrorFormatter.php b/includes/api/ApiErrorFormatter.php index 81ee9b9932..9dfd3705a5 100644 --- a/includes/api/ApiErrorFormatter.php +++ b/includes/api/ApiErrorFormatter.php @@ -237,6 +237,7 @@ class ApiErrorFormatter { */ public function formatException( $exception, array $options = [] ) { return $this->formatMessage( + // @phan-suppress-next-line PhanTypeMismatchArgument $this->getMessageFromException( $exception, $options ), $options['format'] ?? null ); diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 47a6f87296..2c19c7d1aa 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -186,6 +186,7 @@ class ApiQueryLogEvents extends ApiQueryBase { // T71222: MariaDB's optimizer, at least 10.1.37 and .38, likes to choose a wildly bad plan for // some reason for this code path. Tell it not to use the wrong index it wants to pick. + // @phan-suppress-next-line PhanTypeMismatchArgument $this->addOption( 'IGNORE INDEX', [ 'logging' => [ 'times' ] ] ); } diff --git a/includes/api/ApiTag.php b/includes/api/ApiTag.php index bb6c580385..f2b52cd33a 100644 --- a/includes/api/ApiTag.php +++ b/includes/api/ApiTag.php @@ -96,6 +96,7 @@ class ApiTag extends ApiBase { $valid = RecentChange::newFromId( $id ); if ( $valid && $this->getPermissionManager()->isBlockedFrom( $user, $valid->getTitle() ) ) { $idResult['status'] = 'error'; + // @phan-suppress-next-line PhanTypeMismatchArgument $idResult += $this->getErrorFormatter()->formatMessage( ApiMessage::create( 'apierror-blocked', 'blocked', @@ -111,6 +112,7 @@ class ApiTag extends ApiBase { $this->getPermissionManager()->isBlockedFrom( $user, $valid->getPageAsLinkTarget() ) ) { $idResult['status'] = 'error'; + // @phan-suppress-next-line PhanTypeMismatchArgument $idResult += $this->getErrorFormatter()->formatMessage( ApiMessage::create( 'apierror-blocked', 'blocked', diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 373ec11271..4678e1f0cc 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -636,6 +636,7 @@ class ApiUpload extends ApiBase { } ApiResult::setIndexedTagName( $details, 'detail' ); $msg->setApiData( $msg->getApiData() + [ 'details' => $details ] ); + // @phan-suppress-next-line PhanTypeMismatchArgument $this->dieWithError( $msg ); break; diff --git a/includes/block/BlockManager.php b/includes/block/BlockManager.php index 4c2f27ea2e..077bdca7c8 100644 --- a/includes/block/BlockManager.php +++ b/includes/block/BlockManager.php @@ -455,12 +455,14 @@ class BlockManager { // TODO: Improve on simply tracking the first trackable block (T225654) foreach ( $block->getOriginalBlocks() as $originalBlock ) { if ( $this->shouldTrackBlockWithCookie( $originalBlock, $isAnon ) ) { + '@phan-var DatabaseBlock $originalBlock'; $this->setBlockCookie( $originalBlock, $response ); return; } } } else { if ( $this->shouldTrackBlockWithCookie( $block, $isAnon ) ) { + '@phan-var DatabaseBlock $block'; $this->setBlockCookie( $block, $response ); } } diff --git a/includes/filerepo/file/ArchivedFile.php b/includes/filerepo/file/ArchivedFile.php index b4fd176143..a968831b08 100644 --- a/includes/filerepo/file/ArchivedFile.php +++ b/includes/filerepo/file/ArchivedFile.php @@ -438,7 +438,9 @@ class ArchivedFile { function pageCount() { if ( !isset( $this->pageCount ) ) { // @FIXME: callers expect File objects + // @phan-suppress-next-line PhanTypeMismatchArgument if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) { + // @phan-suppress-next-line PhanTypeMismatchArgument $this->pageCount = $this->handler->pageCount( $this ); } else { $this->pageCount = false; diff --git a/includes/http/HttpRequestFactory.php b/includes/http/HttpRequestFactory.php index 8433df6e08..510d26d2bd 100644 --- a/includes/http/HttpRequestFactory.php +++ b/includes/http/HttpRequestFactory.php @@ -59,7 +59,7 @@ class HttpRequestFactory { * - originalRequest Information about the original request (as a WebRequest object or * an associative array with 'ip' and 'userAgent'). * @codingStandardsIgnoreStart - * @phan-param array{timeout?:int,connectTimeout?:int,postData?:array,proxy?:string,noProxy?:bool,sslVerifyHost?:bool,sslVerifyCert?:bool,caInfo?:string,maxRedirects?:int,followRedirects?:bool,userAgent?:string,logger?:\Psr\Logger\LoggerInterface,username?:string,password?:string,originalRequest?:WebRequest|array{ip:string,userAgent:string}} $options + * @phan-param array{timeout?:int,connectTimeout?:int,postData?:array,proxy?:string,noProxy?:bool,sslVerifyHost?:bool,sslVerifyCert?:bool,caInfo?:string,maxRedirects?:int,followRedirects?:bool,userAgent?:string,method?:string,logger?:\Psr\Log\LoggerInterface,username?:string,password?:string,originalRequest?:WebRequest|array{ip:string,userAgent:string}} $options * @codingStandardsIgnoreEnd * @param string $caller The method making this request, for profiling * @throws RuntimeException diff --git a/includes/mail/UserMailer.php b/includes/mail/UserMailer.php index 07830683fd..7b739027f8 100644 --- a/includes/mail/UserMailer.php +++ b/includes/mail/UserMailer.php @@ -393,6 +393,7 @@ class UserMailer { Wikimedia\restoreWarnings(); return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() ); } + '@phan-var Mail_smtp $mail_object'; wfDebug( "Sending mail via PEAR::Mail\n" ); diff --git a/includes/page/MovePageFactory.php b/includes/page/MovePageFactory.php index 2f3fac2e7d..ff7ee4bd44 100644 --- a/includes/page/MovePageFactory.php +++ b/includes/page/MovePageFactory.php @@ -27,7 +27,6 @@ use MovePage; use NamespaceInfo; use RepoGroup; use Title; -use WatchedItemStore; use WatchedItemStoreInterface; use Wikimedia\Rdbms\ILoadBalancer; @@ -44,7 +43,7 @@ class MovePageFactory { /** @var NamespaceInfo */ private $nsInfo; - /** @var WatchedItemStore */ + /** @var WatchedItemStoreInterface */ private $watchedItems; /** @var PermissionManager */ diff --git a/includes/parser/PPDPart_Hash.php b/includes/parser/PPDPart_Hash.php index d4f66f7a48..597f851d4a 100644 --- a/includes/parser/PPDPart_Hash.php +++ b/includes/parser/PPDPart_Hash.php @@ -35,6 +35,7 @@ class PPDPart_Hash extends PPDPart { } else { $accum = []; } + // @phan-suppress-next-line PhanTypeMismatchArgument parent::__construct( $accum ); } } diff --git a/includes/site/SiteImporter.php b/includes/site/SiteImporter.php index 956bdab37e..571b6e44c6 100644 --- a/includes/site/SiteImporter.php +++ b/includes/site/SiteImporter.php @@ -168,6 +168,7 @@ class SiteImporter { $pathTags = $siteElement->getElementsByTagName( 'path' ); for ( $i = 0; $i < $pathTags->length; $i++ ) { $pathElement = $pathTags->item( $i ); + '@phan-var DOMElement $pathElement'; $pathType = $this->getAttributeValue( $pathElement, 'type' ); $path = $pathElement->textContent; @@ -177,6 +178,7 @@ class SiteImporter { $idTags = $siteElement->getElementsByTagName( 'localid' ); for ( $i = 0; $i < $idTags->length; $i++ ) { $idElement = $idTags->item( $i ); + '@phan-var DOMElement $idElement'; $idType = $this->getAttributeValue( $idElement, 'type' ); $id = $idElement->textContent; diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php index 403f5b2538..dedf83abc8 100644 --- a/includes/skins/BaseTemplate.php +++ b/includes/skins/BaseTemplate.php @@ -756,6 +756,7 @@ abstract class BaseTemplate extends QuickTemplate { */ public function getTrail() { return WrappedString::join( "\n", [ + // @phan-suppress-next-line PhanTypeMismatchArgument MWDebug::getDebugHTML( $this->getSkin()->getContext() ), $this->get( 'bottomscripts' ), $this->get( 'reporttime' ) diff --git a/maintenance/refreshFileHeaders.php b/maintenance/refreshFileHeaders.php index db8a19a115..264ba57a29 100644 --- a/maintenance/refreshFileHeaders.php +++ b/maintenance/refreshFileHeaders.php @@ -143,6 +143,10 @@ class RefreshFileHeaders extends Maintenance { $this->output( "Done. Updated headers for $count file(s).\n" ); } + /** + * @param LocalRepo $repo + * @param array $backendOperations + */ protected function updateFileHeaders( $repo, $backendOperations ) { $status = $repo->getBackend()->doQuickOperations( $backendOperations ); -- 2.20.1