Add various null checks when null is not possible to use as argument

Also check for false if needed

Found by phan strict checks

Change-Id: I298204653dfb788515a87978dd8705b6e4f9c775
This commit is contained in:
Umherirrender 2022-03-09 20:14:13 +01:00
parent 8973b02425
commit c259c37033
9 changed files with 25 additions and 14 deletions

View file

@ -203,9 +203,17 @@ class CategoryViewer extends ContextSource {
* @param int $pageLength
*/
public function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
$page = $cat->getPage();
if ( !$page ) {
return;
}
// Subcategory; strip the 'Category' namespace from the link text.
$pageRecord = MediaWikiServices::getInstance()->getPageStore()
->getPageByReference( $cat->getPage() );
->getPageByReference( $page );
if ( !$pageRecord ) {
return;
}
$this->children[] = $this->generateLink(
'subcat',
@ -215,7 +223,7 @@ class CategoryViewer extends ContextSource {
);
$this->children_start_char[] =
$this->getSubcategorySortChar( $cat->getPage(), $sortkey );
$this->getSubcategorySortChar( $page, $sortkey );
}
/**

View file

@ -384,7 +384,7 @@ class CommentParser {
if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
$match[1] = substr( $match[1], 1 );
}
if ( $match[1] !== false && $match[1] !== '' ) {
if ( $match[1] !== false && $match[1] !== null && $match[1] !== '' ) {
if ( preg_match(
$this->contLang->linkTrail(),
$match[3],

View file

@ -3157,7 +3157,7 @@ class OutputPage extends ContextSource {
$module = $rl->getModule( $name );
if ( $module ) {
$group = $module->getGroup();
if ( isset( $exemptGroups[$group] ) ) {
if ( $group !== null && isset( $exemptGroups[$group] ) ) {
// The `noscript` module is excluded from the client
// side registry, no need to set its state either.
// But we still output it. See T291735

View file

@ -121,7 +121,7 @@ class StreamFile {
) {
return 'unknown/unknown';
}
if ( $verifyMimeType && in_array( strtolower( $type ), $mimeTypeExclusions ) ) {
if ( $verifyMimeType && $type !== null && in_array( strtolower( $type ), $mimeTypeExclusions ) ) {
return 'unknown/unknown';
}
}

View file

@ -33,6 +33,7 @@ class HTMLUsersMultiselectField extends HTMLUserTextField {
$userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
$listOfIps = [];
foreach ( $usersArray as $user ) {
$canonicalUser = false;
if ( IPUtils::isIPAddress( $user ) ) {
$parsedIPRange = IPUtils::parseRange( $user );
if ( !in_array( $parsedIPRange, $listOfIps ) ) {
@ -42,7 +43,9 @@ class HTMLUsersMultiselectField extends HTMLUserTextField {
} else {
$canonicalUser = $userNameUtils->getCanonical( $user, UserNameUtils::RIGOR_NONE );
}
$normalizedUsers[] = $canonicalUser;
if ( $canonicalUser !== false ) {
$normalizedUsers[] = $canonicalUser;
}
}
// Remove any duplicate usernames
$uniqueUsers = array_unique( $normalizedUsers );

View file

@ -490,7 +490,7 @@ class MimeAnalyzer implements LoggerAwareInterface {
$callback( $this, $ext, $mime /* by reference */ );
}
if ( isset( $this->mimeTypeAliases[$mime] ) ) {
if ( $mime !== null && isset( $this->mimeTypeAliases[$mime] ) ) {
$mime = $this->mimeTypeAliases[$mime];
}

View file

@ -607,7 +607,7 @@ EOT
}
$renderLangOptions = $this->displayImg->getAvailableLanguages();
if ( count( $renderLangOptions ) >= 1 ) {
if ( $renderLang !== null && count( $renderLangOptions ) >= 1 ) {
$out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $renderLang ) );
}

View file

@ -171,15 +171,15 @@ class SpecialAllPages extends IncludableSpecialPage {
/**
* @param int $namespace (default NS_MAIN)
* @param string $from List all pages from this name
* @param string $to List all pages to this name
* @param string|null $from List all pages from this name
* @param string|null $to List all pages to this name
* @param bool $hideredirects Don't show redirects (default false)
*/
private function showToplevel(
$namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false
$namespace = NS_MAIN, $from = null, $to = null, $hideredirects = false
) {
$from = Title::makeTitleSafe( $namespace, $from );
$to = Title::makeTitleSafe( $namespace, $to );
$from = $from ? Title::makeTitleSafe( $namespace, $from ) : null;
$to = $to ? Title::makeTitleSafe( $namespace, $to ) : null;
$from = ( $from && $from->isLocal() ) ? $from->getDBkey() : null;
$to = ( $to && $to->isLocal() ) ? $to->getDBkey() : null;

View file

@ -872,7 +872,7 @@ class SpecialVersion extends SpecialPage {
$licenseName = null;
if ( isset( $extension['license-name'] ) ) {
$licenseName = new HtmlArmor( $out->parseInlineAsInterface( $extension['license-name'] ) );
} elseif ( ExtensionInfo::getLicenseFileNames( $extensionPath ) ) {
} elseif ( $extensionPath !== null && ExtensionInfo::getLicenseFileNames( $extensionPath ) ) {
$licenseName = $this->msg( 'version-ext-license' )->text();
}
if ( $licenseName !== null ) {