Fix using null for a non-nullable argument
authorDaimona Eaytoy <daimona.wiki@gmail.com>
Sun, 15 Sep 2019 13:53:14 +0000 (15:53 +0200)
committerKrinkle <krinklemail@gmail.com>
Thu, 19 Sep 2019 16:55:03 +0000 (16:55 +0000)
These are reported by phan as PhanTypeMismatchArgumentNullableInternal
when null_casts_as_any_type is disabled.

Change-Id: I85076ee31c1bfc59a19600e84da0d915e425890a

includes/GlobalFunctions.php
includes/exception/MWExceptionHandler.php
includes/libs/mime/MimeAnalyzer.php
includes/parser/Parser.php
includes/specials/SpecialMyLanguage.php
includes/upload/UploadBase.php

index 3b4e657..2ed385e 100644 (file)
@@ -518,7 +518,7 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
                }
        }
 
-       $defaultProtoWithoutSlashes = substr( $defaultProto, 0, -2 );
+       $defaultProtoWithoutSlashes = $defaultProto !== null ? substr( $defaultProto, 0, -2 ) : '';
 
        if ( substr( $url, 0, 2 ) == '//' ) {
                $url = $defaultProtoWithoutSlashes . $url;
index d7c5a85..4a72d72 100644 (file)
@@ -350,7 +350,7 @@ class MWExceptionHandler {
 
                // Look at message to see if this is a class not found failure
                // HHVM: Class undefined: foo
-               // PHP5: Class 'foo' not found
+               // PHP7: Class 'foo' not found
                if ( preg_match( "/Class (undefined: \w+|'\w+' not found)/", $message ) ) {
                        // phpcs:disable Generic.Files.LineLength
                        $msg = <<<TXT
index bafe5e3..6fca043 100644 (file)
@@ -1089,7 +1089,7 @@ EOT;
 
                // Special code for ogg - detect if it's video (theora),
                // else label it as sound.
-               if ( $mime == 'application/ogg' && file_exists( $path ) ) {
+               if ( $mime == 'application/ogg' && is_string( $path ) && file_exists( $path ) ) {
                        // Read a chunk of the file
                        $f = fopen( $path, "rt" );
                        if ( !$f ) {
index b27338c..ec1628f 100644 (file)
@@ -2312,6 +2312,11 @@ class Parser {
                $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
                $s = substr( $s, 1 );
 
+               if ( is_null( $this->mTitle ) ) {
+                       throw new MWException( __METHOD__ . ": \$this->mTitle is null\n" );
+               }
+               $nottalk = !$this->mTitle->isTalkPage();
+
                $useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension();
                $e2 = null;
                if ( $useLinkPrefixExtension ) {
@@ -2319,14 +2324,6 @@ class Parser {
                        # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
                        $charset = $this->contLang->linkPrefixCharset();
                        $e2 = "/^((?>.*[^$charset]|))(.+)$/sDu";
-               }
-
-               if ( is_null( $this->mTitle ) ) {
-                       throw new MWException( __METHOD__ . ": \$this->mTitle is null\n" );
-               }
-               $nottalk = !$this->mTitle->isTalkPage();
-
-               if ( $useLinkPrefixExtension ) {
                        $m = [];
                        if ( preg_match( $e2, $s, $m ) ) {
                                $first_prefix = $m[2];
index 537db9e..408bd92 100644 (file)
@@ -71,14 +71,14 @@ class SpecialMyLanguage extends RedirectSpecialArticle {
                if ( $subpage !== null ) {
                        $provided = Title::newFromText( $subpage );
                        $base = $provided;
-               }
 
-               if ( $provided && strpos( $subpage, '/' ) !== false ) {
-                       $pos = strrpos( $subpage, '/' );
-                       $basepage = substr( $subpage, 0, $pos );
-                       $code = substr( $subpage, $pos + 1 );
-                       if ( strlen( $code ) && Language::isKnownLanguageTag( $code ) ) {
-                               $base = Title::newFromText( $basepage );
+                       if ( $provided && strpos( $subpage, '/' ) !== false ) {
+                               $pos = strrpos( $subpage, '/' );
+                               $basepage = substr( $subpage, 0, $pos );
+                               $code = substr( $subpage, $pos + 1 );
+                               if ( strlen( $code ) && Language::isKnownLanguageTag( $code ) ) {
+                                       $base = Title::newFromText( $basepage );
+                               }
                        }
                }
 
index d7dfffa..f60c4e3 100644 (file)
@@ -1316,7 +1316,7 @@ abstract class UploadBase {
                        $enc = null;
                }
 
-               if ( $enc ) {
+               if ( $enc !== null ) {
                        $chunk = iconv( $enc, "ASCII//IGNORE", $chunk );
                }