From: Derick Alangi Date: Sat, 2 Mar 2019 15:47:40 +0000 (+0100) Subject: Title: Minor clean up for stricter checks, casting style, and doc types X-Git-Tag: 1.34.0-rc.0~2623^2 X-Git-Url: http://git.cyclocoop.org/%28%5B%5E//%22%22?a=commitdiff_plain;h=95da4e0d79d11abb9576a6a1b464fc278aaeb8ea;p=lhc%2Fweb%2Fwiklou.git Title: Minor clean up for stricter checks, casting style, and doc types These improvements touch areas around cleaning up deprecated functions such as intval(), strval() into casting with (int), (string), etc. If such improvements is welcomed into the Title class, I can make more of such but for now, I've just made a few, like 1/20 of these kind of changes in the file so that, if it's merged and encouraged to continue, I'll cleanup the file. Or as proposed on this patch, phpcs rules can be used to handle such cases. Change-Id: Ib90e880cb124e765379ddad531d4c89289d364de --- diff --git a/includes/Title.php b/includes/Title.php index 0b74a17a12..82e79b379c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -37,7 +37,7 @@ use MediaWiki\MediaWikiServices; * and does not rely on global state or the database. */ class Title implements LinkTarget, IDBAccessObject { - /** @var MapCacheLRU */ + /** @var MapCacheLRU|null */ private static $titleCache = null; /** @@ -140,7 +140,7 @@ class Title implements LinkTarget, IDBAccessObject { * Only public to share cache with TitleFormatter * * @private - * @var string + * @var string|null */ public $prefixedText = null; @@ -173,10 +173,10 @@ class Title implements LinkTarget, IDBAccessObject { * the database or false if not loaded, yet. */ private $mDbPageLanguage = false; - /** @var TitleValue A corresponding TitleValue object */ + /** @var TitleValue|null A corresponding TitleValue object */ private $mTitleValue = null; - /** @var bool Would deleting this page be a big deletion? */ + /** @var bool|null Would deleting this page be a big deletion? */ private $mIsBigDeletion = null; // @} @@ -219,7 +219,7 @@ class Title implements LinkTarget, IDBAccessObject { * @return Title|null Title, or null on an error */ public static function newFromDBkey( $key ) { - $t = new Title(); + $t = new self(); $t->mDbkeyform = $key; try { @@ -287,7 +287,7 @@ class Title implements LinkTarget, IDBAccessObject { } try { - return self::newFromTextThrow( strval( $text ), $defaultNamespace ); + return self::newFromTextThrow( (string)$text, $defaultNamespace ); } catch ( MalformedTitleException $ex ) { return null; } @@ -337,7 +337,7 @@ class Title implements LinkTarget, IDBAccessObject { $t = new Title(); $t->mDbkeyform = strtr( $filteredText, ' ', '_' ); - $t->mDefaultNamespace = intval( $defaultNamespace ); + $t->mDefaultNamespace = (int)$defaultNamespace; $t->secureAndSplit(); if ( $defaultNamespace == NS_MAIN ) { @@ -385,7 +385,7 @@ class Title implements LinkTarget, IDBAccessObject { * @return MapCacheLRU */ private static function getTitleCache() { - if ( self::$titleCache == null ) { + if ( self::$titleCache === null ) { self::$titleCache = new MapCacheLRU( self::CACHE_MAX ); } return self::$titleCache; @@ -499,7 +499,7 @@ class Title implements LinkTarget, IDBAccessObject { $this->mLatestID = (int)$row->page_latest; } if ( !$this->mForcedContentModel && isset( $row->page_content_model ) ) { - $this->mContentModel = strval( $row->page_content_model ); + $this->mContentModel = (string)$row->page_content_model; } elseif ( !$this->mForcedContentModel ) { $this->mContentModel = false; # initialized lazily in getContentModel() } @@ -546,7 +546,7 @@ class Title implements LinkTarget, IDBAccessObject { $t = new Title(); $t->mInterwiki = $interwiki; $t->mFragment = $fragment; - $t->mNamespace = $ns = intval( $ns ); + $t->mNamespace = $ns = (int)$ns; $t->mDbkeyform = strtr( $title, ' ', '_' ); $t->mArticleID = ( $ns >= 0 ) ? -1 : 0; $t->mUrlform = wfUrlencode( $t->mDbkeyform );