phan: Enable PhanTypeMismatchArgument issue
authorUmherirrender <umherirrender_de.wp@web.de>
Tue, 18 Jun 2019 20:26:00 +0000 (22:26 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 19 Sep 2019 18:11:42 +0000 (20:11 +0200)
Bug: T231636
Depends-On: I5de4f8f32a47c3f41c990ffe2ebd091fc23d1a58
Change-Id: I34d65fe3ff1916f2af675f0b1f19641b0cdfadc0

17 files changed:
.phan/config.php
includes/EditPage.php
includes/MovePage.php
includes/api/ApiBase.php
includes/api/ApiErrorFormatter.php
includes/api/ApiQueryLogEvents.php
includes/api/ApiTag.php
includes/api/ApiUpload.php
includes/block/BlockManager.php
includes/filerepo/file/ArchivedFile.php
includes/http/HttpRequestFactory.php
includes/mail/UserMailer.php
includes/page/MovePageFactory.php
includes/parser/PPDPart_Hash.php
includes/site/SiteImporter.php
includes/skins/BaseTemplate.php
maintenance/refreshFileHeaders.php

index 56a8ccb..0fdefe0 100644 (file)
@@ -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
index 10eea89..9182300 100644 (file)
@@ -1156,7 +1156,7 @@ class EditPage {
                        $out->showErrorPage(
                                'modeleditnotsupported-title',
                                'modeleditnotsupported-text',
-                               $modelName
+                               [ $modelName ]
                        );
                        return false;
                }
index 634e7af..59baae7 100644 (file)
@@ -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(
index 056d10c..7518008 100644 (file)
@@ -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] )
index 81ee9b9..9dfd370 100644 (file)
@@ -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
                );
index 47a6f87..2c19c7d 100644 (file)
@@ -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' ] ] );
                }
 
index bb6c580..f2b52cd 100644 (file)
@@ -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',
index 373ec11..4678e1f 100644 (file)
@@ -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;
 
index 4c2f27e..077bdca 100644 (file)
@@ -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 );
                                                }
                                        }
index b4fd176..a968831 100644 (file)
@@ -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;
index 8433df6..510d26d 100644 (file)
@@ -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
index 0783068..7b73902 100644 (file)
@@ -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" );
 
index 2f3fac2..ff7ee4b 100644 (file)
@@ -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 */
index d4f66f7..597f851 100644 (file)
@@ -35,6 +35,7 @@ class PPDPart_Hash extends PPDPart {
                } else {
                        $accum = [];
                }
+               // @phan-suppress-next-line PhanTypeMismatchArgument
                parent::__construct( $accum );
        }
 }
index 956bdab..571b6e4 100644 (file)
@@ -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;
 
index 403f5b2..dedf83a 100644 (file)
@@ -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' )
index db8a19a..264ba57 100644 (file)
@@ -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 );