From b138a9b228ea75814dfad26f4b6fed9360732167 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 15 Sep 2019 15:53:14 +0200 Subject: [PATCH] Fix using null for a non-nullable argument These are reported by phan as PhanTypeMismatchArgumentNullableInternal when null_casts_as_any_type is disabled. Change-Id: I85076ee31c1bfc59a19600e84da0d915e425890a --- includes/GlobalFunctions.php | 2 +- includes/exception/MWExceptionHandler.php | 2 +- includes/libs/mime/MimeAnalyzer.php | 2 +- includes/parser/Parser.php | 13 +++++-------- includes/specials/SpecialMyLanguage.php | 14 +++++++------- includes/upload/UploadBase.php | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3b4e657f75..2ed385e225 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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; diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php index d7c5a855bd..4a72d72d6b 100644 --- a/includes/exception/MWExceptionHandler.php +++ b/includes/exception/MWExceptionHandler.php @@ -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 = <<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]; diff --git a/includes/specials/SpecialMyLanguage.php b/includes/specials/SpecialMyLanguage.php index 537db9ee1d..408bd92883 100644 --- a/includes/specials/SpecialMyLanguage.php +++ b/includes/specials/SpecialMyLanguage.php @@ -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 ); + } } } diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index d7dfffa39f..f60c4e3c10 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1316,7 +1316,7 @@ abstract class UploadBase { $enc = null; } - if ( $enc ) { + if ( $enc !== null ) { $chunk = iconv( $enc, "ASCII//IGNORE", $chunk ); } -- 2.20.1