From: Daimona Eaytoy Date: Sun, 15 Sep 2019 13:53:14 +0000 (+0200) Subject: Fix using null for a non-nullable argument X-Git-Tag: 1.34.0-rc.0~151 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%22http:/wikimediafoundation.org/fundraising/%7B%7B%20url_for%28%27user_settings%27%2C%20userid=session.userid%29%20%7D%7D?a=commitdiff_plain;h=b138a9b228ea75814dfad26f4b6fed9360732167;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 ); }