Fix/suppress misc phan errors (#2)
authorKunal Mehta <legoktm@member.fsf.org>
Fri, 22 Mar 2019 01:12:50 +0000 (18:12 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Fri, 5 Apr 2019 23:12:18 +0000 (16:12 -0700)
* Title: phan false positive
* McrUndoAction: fixed improper use of @param
* UploadSourceAdapter: fixed wrong type
* XmlTypeCheck: Use null so phan doesn't think we're trying to call the
function ''
* Database: phan false positive
* SpecialBlock: Use phan's advanced type documentation so phan knows
specifically what's being returned
* ChangesListSpecialPage: phan false positive
* BatchRowUpdate: Have default callback take a parameter so phan doesn't
think too many arguments are being passed
* MimeAnalyzer: left FIXME for relying on PHP 7.1 unpack() signature
* LanguageConverter: Specify types for $mTables since phan couldn't
determine it automatically
* preprocessorFuzzTest: Implement User::load() method signature

Change-Id: I08080ab636c5fe67ea6a4e14b2212d7523606e21

13 files changed:
.phan/config.php
includes/Title.php
includes/actions/McrUndoAction.php
includes/htmlform/OOUIHTMLForm.php
includes/import/UploadSourceAdapter.php
includes/libs/mime/MimeAnalyzer.php
includes/libs/mime/XmlTypeCheck.php
includes/libs/rdbms/database/Database.php
includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialBlock.php
includes/utils/BatchRowUpdate.php
languages/LanguageConverter.php
maintenance/preprocessorFuzzTest.php

index 2c0035e..e0395cb 100644 (file)
@@ -81,33 +81,19 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [
        "PhanCommentParamWithoutRealParam",
        // approximate error count: 2
        "PhanCompatibleNegativeStringOffset",
-       // approximate error count: 1
-       "PhanEmptyFQSENInCallable",
-       // approximate error count: 1
-       "PhanInvalidCommentForDeclarationType",
-       // approximate error count: 6
-       "PhanNonClassMethodCall",
        // approximate error count: 21
        "PhanParamReqAfterOpt",
-       // approximate error count: 27
+       // approximate error count: 26
        "PhanParamSignatureMismatch",
        // approximate error count: 4
        "PhanParamSignatureMismatchInternal",
-       // approximate error count: 1
-       "PhanParamSignatureRealMismatchTooFewParameters",
-       // approximate error count: 1
-       "PhanParamSuspiciousOrder",
        // approximate error count: 127
        "PhanParamTooMany",
        // approximate error count: 2
-       "PhanParamTooManyCallable",
-       // approximate error count: 1
-       "PhanParamTooManyInternal",
-       // approximate error count: 2
        "PhanPluginDuplicateExpressionBinaryOp",
        // approximate error count: 2
        "PhanTraitParentReference",
-       // approximate error count: 27
+       // approximate error count: 26
        "PhanTypeArraySuspicious",
        // approximate error count: 33
        "PhanTypeArraySuspiciousNullable",
@@ -133,7 +119,7 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [
        "PhanTypeInvalidRightOperandOfIntegerOp",
        // approximate error count: 152
        "PhanTypeMismatchArgument",
-       // approximate error count: 28
+       // approximate error count: 27
        "PhanTypeMismatchArgumentInternal",
        // approximate error count: 1
        "PhanTypeMismatchBitwiseBinaryOperands",
@@ -143,7 +129,7 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [
        "PhanTypeMismatchDimFetch",
        // approximate error count: 10
        "PhanTypeMismatchForeach",
-       // approximate error count: 77
+       // approximate error count: 78
        "PhanTypeMismatchProperty",
        // approximate error count: 88
        "PhanTypeMismatchReturn",
@@ -171,7 +157,7 @@ $cfg['suppress_issue_types'] = array_merge( $cfg['suppress_issue_types'], [
        "PhanUndeclaredVariableAssignOp",
        // approximate error count: 55
        "PhanUndeclaredVariableDim",
-       // approximate error count: 4
+       // approximate error count: 3
        "PhanUnextractableAnnotationElementName",
        // approximate error count: 4
        "PhanUnextractableAnnotationSuffix",
index d517b85..3d54750 100644 (file)
@@ -731,6 +731,7 @@ class Title implements LinkTarget, IDBAccessObject {
                                // Allow unicode if a single high-bit character appears
                                $r0 = sprintf( '\x%02x', $ord0 );
                                $allowUnicode = true;
+                               // @phan-suppress-next-line PhanParamSuspiciousOrder false positive
                        } elseif ( strpos( '-\\[]^', $d0 ) !== false ) {
                                $r0 = '\\' . $d0;
                        } else {
index b0f89dc..e9de846 100644 (file)
@@ -30,7 +30,7 @@ class McrUndoAction extends FormAction {
 
        protected $undo = 0, $undoafter = 0, $cur = 0;
 
-       /** @param RevisionRecord|null */
+       /** @var RevisionRecord|null */
        protected $curRev = null;
 
        public function getName() {
index 738db09..e21d783 100644 (file)
@@ -145,6 +145,10 @@ class OOUIHTMLForm extends HTMLForm {
                        [ 'class' => 'mw-htmlform-submit-buttons' ], "\n$buttons" ) . "\n";
        }
 
+       /**
+        * @inheritDoc
+        * @return OOUI\PanelLayout
+        */
        protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
                // to get a user visible effect, wrap the fieldset into a framed panel layout
                $layout = new OOUI\PanelLayout( [
index ccacbe4..7ac895c 100644 (file)
@@ -32,7 +32,7 @@ class UploadSourceAdapter {
        /** @var array */
        public static $sourceRegistrations = [];
 
-       /** @var string */
+       /** @var ImportSource */
        private $mSource;
 
        /** @var string */
index e08da61..413fb2a 100644 (file)
@@ -806,6 +806,8 @@ EOT;
                if ( $eocdrPos !== false ) {
                        $this->logger->info( __METHOD__ . ": ZIP signature present in $file\n" );
                        // Check if it really is a ZIP file, make sure the EOCDR is at the end (T40432)
+                       // FIXME: unpack()'s third argument was added in PHP 7.1
+                       // @phan-suppress-next-line PhanParamTooManyInternal
                        $commentLength = unpack( "n", $tail, $eocdrPos + 20 )[0];
                        if ( $eocdrPos + 22 + $commentLength !== strlen( $tail ) ) {
                                $this->logger->info( __METHOD__ . ": ZIP EOCDR not at end. Not a ZIP file." );
index 746f3f5..0b52391 100644 (file)
@@ -72,7 +72,7 @@ class XmlTypeCheck {
         * Additional parsing options
         */
        private $parserOptions = [
-               'processing_instruction_handler' => '',
+               'processing_instruction_handler' => null,
                'external_dtd_handler' => '',
                'dtd_handler' => '',
                'require_safe_dtd' => true
index 2739205..a839946 100644 (file)
@@ -3580,6 +3580,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                list( $phpCallback ) = $callback;
                                $this->clearFlag( self::DBO_TRX ); // make each query its own transaction
                                try {
+                                       // @phan-suppress-next-line PhanParamTooManyCallable
                                        call_user_func( $phpCallback, $trigger, $this );
                                } catch ( Exception $ex ) {
                                        call_user_func( $this->errorLogger, $ex );
index 82bc84d..9e7e21d 100644 (file)
@@ -1072,6 +1072,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                $filterDefinition = $this->transformFilterDefinition( $filterDefinition );
                        }
 
+                       // @phan-suppress-next-line PhanNonClassMethodCall
                        $this->registerFilterGroup( new $className( $groupDefinition ) );
                }
        }
index b558d5e..155d6a4 100644 (file)
@@ -620,6 +620,7 @@ class SpecialBlock extends FormSpecialPage {
         *     the HTMLForm
         * @param WebRequest|null $request Optionally try and get data from a request too
         * @return array [ User|string|null, Block::TYPE_ constant|null ]
+        * @phan-return array{0:User|string|null,1:int|null}
         */
        public static function getTargetAndType( $par, WebRequest $request = null ) {
                $i = 0;
index f42b5a0..f2bc615 100644 (file)
@@ -77,7 +77,7 @@ class BatchRowUpdate {
                $this->reader = $reader;
                $this->writer = $writer;
                $this->generator = $generator;
-               $this->output = function () {
+               $this->output = function ( $text ) {
                }; // nop
        }
 
index 8aa7c87..c5ff9d6 100644 (file)
@@ -60,7 +60,13 @@ class LanguageConverter {
        public $mVariantFallbacks;
        public $mVariantNames;
        public $mTablesLoaded = false;
+
+       /**
+        * @var ReplacementArray[]
+        * @phan-var array<string,ReplacementArray>
+        */
        public $mTables;
+
        // 'bidirectional' 'unidirectional' 'disable' for each variant
        public $mManualLevel;
 
index d5d27ad..8df01e6 100644 (file)
@@ -239,7 +239,7 @@ class PPFuzzTest {
 class PPFuzzUser extends User {
        public $ppfz_test, $mDataLoaded;
 
-       function load() {
+       function load( $flags = null ) {
                if ( $this->mDataLoaded ) {
                        return;
                }