Title: Minor clean up for stricter checks, casting style, and doc types
authorDerick Alangi <alangiderick@gmail.com>
Sat, 2 Mar 2019 15:47:40 +0000 (16:47 +0100)
committerD3r1ck01 <alangiderick@gmail.com>
Wed, 6 Mar 2019 15:10:46 +0000 (15:10 +0000)
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

includes/Title.php

index 0b74a17..82e79b3 100644 (file)
@@ -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 );