No variable assignment on return statement
authorumherirrender <umherirrender_de.wp@web.de>
Wed, 1 Jan 2014 18:56:08 +0000 (19:56 +0100)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 2 Jan 2014 09:43:35 +0000 (09:43 +0000)
Split the variable assignment and the return statement in two lines for
better readability.

When there was two return statements in one method the logic was swapped
to have only one return statement.

Change-Id: Id7a01b4a2df96036435f9e1a9be5678dd124b0af

14 files changed:
includes/EditPage.php
includes/Linker.php
includes/Title.php
includes/WikiFilePage.php
includes/WikiPage.php
includes/logging/DeleteLogFormatter.php
includes/logging/LogFormatter.php
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderFileModule.php
includes/resourceloader/ResourceLoaderStartUpModule.php
includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
includes/resourceloader/ResourceLoaderUserOptionsModule.php
includes/upload/UploadBase.php
languages/LanguageConverter.php

index f86cae4..ba49378 100644 (file)
@@ -1913,12 +1913,10 @@ class EditPage {
        function getBaseRevision() {
                if ( !$this->mBaseRevision ) {
                        $db = wfGetDB( DB_MASTER );
-                       $baseRevision = Revision::loadFromTimestamp(
+                       $this->mBaseRevision = Revision::loadFromTimestamp(
                                $db, $this->mTitle, $this->edittime );
-                       return $this->mBaseRevision = $baseRevision;
-               } else {
-                       return $this->mBaseRevision;
                }
+               return $this->mBaseRevision;
        }
 
        /**
index 27f8ab4..9e489e7 100644 (file)
@@ -2137,7 +2137,8 @@ class Linker {
                }
 
                wfProfileOut( __METHOD__ );
-               return self::$accesskeycache[$name] = $accesskey;
+               self::$accesskeycache[$name] = $accesskey;
+               return self::$accesskeycache[$name];
        }
 
        /**
index 5ab9e94..1c63e14 100644 (file)
@@ -2892,15 +2892,15 @@ class Title {
                # alone to cache the result.  There's no point in having it hanging
                # around uninitialized in every Title object; therefore we only add it
                # if needed and don't declare it statically.
-               if ( isset( $this->mHasSubpages ) ) {
-                       return $this->mHasSubpages;
+               if ( !isset( $this->mHasSubpages ) ) {
+                       $this->mHasSubpages = false;
+                       $subpages = $this->getSubpages( 1 );
+                       if ( $subpages instanceof TitleArray ) {
+                               $this->mHasSubpages = (bool)$subpages->count();
+                       }
                }
 
-               $subpages = $this->getSubpages( 1 );
-               if ( $subpages instanceof TitleArray ) {
-                       return $this->mHasSubpages = (bool)$subpages->count();
-               }
-               return $this->mHasSubpages = false;
+               return $this->mHasSubpages;
        }
 
        /**
@@ -2922,7 +2922,7 @@ class Title {
                if ( $limit > -1 ) {
                        $options['LIMIT'] = $limit;
                }
-               return $this->mSubpages = TitleArray::newFromResult(
+               $this->mSubpages = TitleArray::newFromResult(
                        $dbr->select( 'page',
                                array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ),
                                $conds,
@@ -2930,6 +2930,7 @@ class Title {
                                $options
                        )
                );
+               return $this->mSubpages;
        }
 
        /**
@@ -2990,7 +2991,8 @@ class Title {
         */
        public function getArticleID( $flags = 0 ) {
                if ( $this->getNamespace() < 0 ) {
-                       return $this->mArticleID = 0;
+                       $this->mArticleID = 0;
+                       return $this->mArticleID;
                }
                $linkCache = LinkCache::singleton();
                if ( $flags & self::GAID_FOR_UPDATE ) {
@@ -3019,7 +3021,8 @@ class Title {
                }
                # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
-                       return $this->mRedirect = false;
+                       $this->mRedirect = false;
+                       return $this->mRedirect;
                }
 
                $linkCache = LinkCache::singleton();
@@ -3031,7 +3034,8 @@ class Title {
                        # LinkCache as appropriate, or use $flags = Title::GAID_FOR_UPDATE. If that flag is
                        # set, then LinkCache will definitely be up to date here, since getArticleID() forces
                        # LinkCache to refresh its data from the master.
-                       return $this->mRedirect = false;
+                       $this->mRedirect = false;
+                       return $this->mRedirect;
                }
 
                $this->mRedirect = (bool)$cached;
@@ -3052,13 +3056,15 @@ class Title {
                }
                # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
-                       return $this->mLength = 0;
+                       $this->mLength = 0;
+                       return $this->mLength;
                }
                $linkCache = LinkCache::singleton();
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own, as for isRedirect()
-                       return $this->mLength = 0;
+                       $this->mLength = 0;
+                       return $this->mLength;
                }
 
                $this->mLength = intval( $cached );
@@ -3078,14 +3084,16 @@ class Title {
                }
                # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
-                       return $this->mLatestID = 0;
+                       $this->mLatestID = 0;
+                       return $this->mLatestID;
                }
                $linkCache = LinkCache::singleton();
                $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own, as for isRedirect()
-                       return $this->mLatestID = 0;
+                       $this->mLatestID = 0;
+                       return $this->mLatestID;
                }
 
                $this->mLatestID = intval( $cached );
@@ -4649,7 +4657,8 @@ class Title {
                        return $this->mNotificationTimestamp[$uid];
                }
                if ( !$uid || !$wgShowUpdatedMarker || !$user->isAllowed( 'viewmywatchlist' ) ) {
-                       return $this->mNotificationTimestamp[$uid] = false;
+                       $this->mNotificationTimestamp[$uid] = false;
+                       return $this->mNotificationTimestamp[$uid];
                }
                // Don't cache too much!
                if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) {
index 2b192b0..817f0fa 100644 (file)
@@ -85,7 +85,8 @@ class WikiFilePage extends WikiPage {
                if ( $from == $to ) {
                        return null;
                }
-               return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
+               $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
+               return $this->mRedirectTarget;
        }
 
        /**
@@ -142,7 +143,8 @@ class WikiFilePage extends WikiPage {
                }
                $hash = $this->mFile->getSha1();
                if ( !( $hash ) ) {
-                       return $this->mDupes = array();
+                       $this->mDupes = array();
+                       return $this->mDupes;
                }
                $dupes = RepoGroup::singleton()->findBySha1( $hash );
                // Remove duplicates with self and non matching file sizes
index d4acb6f..f0a58d3 100644 (file)
@@ -908,13 +908,15 @@ class WikiPage implements Page, IDBAccessObject {
 
                // rd_fragment and rd_interwiki were added later, populate them if empty
                if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) {
-                       return $this->mRedirectTarget = Title::makeTitle(
+                       $this->mRedirectTarget = Title::makeTitle(
                                $row->rd_namespace, $row->rd_title,
                                $row->rd_fragment, $row->rd_interwiki );
+                       return $this->mRedirectTarget;
                }
 
                // This page doesn't have an entry in the redirect table
-               return $this->mRedirectTarget = $this->insertRedirect();
+               $this->mRedirectTarget = $this->insertRedirect();
+               return $this->mRedirectTarget;
        }
 
        /**
index d761a87..b658ac1 100644 (file)
@@ -79,13 +79,16 @@ class DeleteLogFormatter extends LogFormatter {
                                $count = count( explode( ',', $params[$paramStart] ) );
                                $newParams[4] = $this->context->getLanguage()->formatNum( $count );
 
-                               return $this->parsedParametersDeleteLog = $newParams;
+                               $this->parsedParametersDeleteLog = $newParams;
+                               return $this->parsedParametersDeleteLog;
                        } else {
-                               return $this->parsedParametersDeleteLog = array_slice( $params, 0, 3 );
+                               $this->parsedParametersDeleteLog = array_slice( $params, 0, 3 );
+                               return $this->parsedParametersDeleteLog;
                        }
                }
 
-               return $this->parsedParametersDeleteLog = $params;
+               $this->parsedParametersDeleteLog = $params;
+               return $this->parsedParametersDeleteLog;
        }
 
        protected function parseBitField( $string ) {
index 084a4b2..9e7f056 100644 (file)
@@ -455,7 +455,8 @@ class LogFormatter {
                // Bad things happens if the numbers are not in correct order
                ksort( $params );
 
-               return $this->parsedParameters = $params;
+               $this->parsedParameters = $params;
+               return $this->parsedParameters;
        }
 
        /**
@@ -737,7 +738,8 @@ class LegacyLogFormatter extends LogFormatter {
                }
 
                if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
-                       return $this->revert = '';
+                       $this->revert = '';
+                       return $this->revert;
                }
 
                $title = $this->entry->getTarget();
index 3b072f9..08b1ac1 100644 (file)
@@ -1130,11 +1130,11 @@ class ResourceLoader {
        public static function inDebugMode() {
                global $wgRequest, $wgResourceLoaderDebug;
                static $retval = null;
-               if ( !is_null( $retval ) ) {
-                       return $retval;
+               if ( is_null( $retval ) ) {
+                       $retval = $wgRequest->getFuzzyBool( 'debug',
+                               $wgRequest->getCookie( 'resourceLoaderDebug', '', $wgResourceLoaderDebug ) );
                }
-               return $retval = $wgRequest->getFuzzyBool( 'debug',
-                       $wgRequest->getCookie( 'resourceLoaderDebug', '', $wgResourceLoaderDebug ) );
+               return $retval;
        }
 
        /**
index 43330da..eaff86f 100644 (file)
@@ -454,8 +454,9 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                // If a module is nothing but a list of dependencies, we need to avoid
                // giving max() an empty array
                if ( count( $files ) === 0 ) {
+                       $this->modifiedTime[$context->getHash()] = 1;
                        wfProfileOut( __METHOD__ );
-                       return $this->modifiedTime[$context->getHash()] = 1;
+                       return $this->modifiedTime[$context->getHash()];
                }
 
                wfProfileIn( __METHOD__ . '-filemtime' );
index 93c5d1b..d0c3068 100644 (file)
@@ -273,7 +273,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        $module = $loader->getModule( $name );
                        $time = max( $time, $module->getModifiedTime( $context ) );
                }
-               return $this->modifiedTime[$hash] = $time;
+               $this->modifiedTime[$hash] = $time;
+               return $this->modifiedTime[$hash];
        }
 
        /* Methods */
index aafe432..a9d1076 100644 (file)
@@ -41,12 +41,12 @@ class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
         */
        public function getModifiedTime( ResourceLoaderContext $context ) {
                $hash = $context->getHash();
-               if ( isset( $this->modifiedTime[$hash] ) ) {
-                       return $this->modifiedTime[$hash];
+               if ( !isset( $this->modifiedTime[$hash] ) ) {
+                       global $wgUser;
+                       $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
                }
 
-               global $wgUser;
-               return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
+               return $this->modifiedTime[$hash];
        }
 
        /**
index 1df8c56..3686bea 100644 (file)
@@ -43,12 +43,12 @@ class ResourceLoaderUserOptionsModule extends ResourceLoaderModule {
         */
        public function getModifiedTime( ResourceLoaderContext $context ) {
                $hash = $context->getHash();
-               if ( isset( $this->modifiedTime[$hash] ) ) {
-                       return $this->modifiedTime[$hash];
+               if ( !isset( $this->modifiedTime[$hash] ) ) {
+                       global $wgUser;
+                       $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
                }
 
-               global $wgUser;
-               return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
+               return $this->modifiedTime[$hash];
        }
 
        /**
index a6c3421..3d2b3f4 100644 (file)
@@ -723,7 +723,8 @@ abstract class UploadBase {
                # exclamation mark, so restrict file name to 240 bytes.
                if ( strlen( $this->mFilteredName ) > 240 ) {
                        $this->mTitleError = self::FILENAME_TOO_LONG;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
                /**
@@ -736,7 +737,8 @@ abstract class UploadBase {
                $nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName );
                if ( is_null( $nt ) ) {
                        $this->mTitleError = self::ILLEGAL_FILENAME;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
                $this->mFilteredName = $nt->getDBkey();
 
@@ -777,19 +779,22 @@ abstract class UploadBase {
 
                if ( $this->mFinalExtension == '' ) {
                        $this->mTitleError = self::FILETYPE_MISSING;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                } elseif ( $blackListedExtensions ||
                                ( $wgCheckFileExtensions && $wgStrictFileExtensions &&
                                        !$this->checkFileExtensionList( $ext, $wgFileExtensions ) ) ) {
                        $this->mBlackListedExtensions = $blackListedExtensions;
                        $this->mTitleError = self::FILETYPE_BADTYPE;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
                // Windows may be broken with special characters, see bug XXX
                if ( wfIsWindows() && !preg_match( '/^[\x0-\x7f]*$/', $nt->getText() ) ) {
                        $this->mTitleError = self::WINDOWS_NONASCII_FILENAME;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
                # If there was more than one "extension", reassemble the base
@@ -802,10 +807,12 @@ abstract class UploadBase {
 
                if ( strlen( $partname ) < 1 ) {
                        $this->mTitleError = self::MIN_LENGTH_PARTNAME;
-                       return $this->mTitle = null;
+                       $this->mTitle = null;
+                       return $this->mTitle;
                }
 
-               return $this->mTitle = $nt;
+               $this->mTitle = $nt;
+               return $this->mTitle;
        }
 
        /**
index cdaab2c..cec9ddb 100644 (file)
@@ -236,7 +236,8 @@ class LanguageConverter {
                        $ret = $wgRequest->getVal( 'uselang' );
                }
 
-               return $this->mURLVariant = $this->validateVariant( $ret );
+               $this->mURLVariant = $this->validateVariant( $ret );
+               return $this->mURLVariant;
        }
 
        /**
@@ -269,7 +270,8 @@ class LanguageConverter {
                        $ret = $wgUser->getOption( 'language' );
                }
 
-               return $this->mUserVariant = $this->validateVariant( $ret );
+               $this->mUserVariant = $this->validateVariant( $ret );
+               return $this->mUserVariant;
        }
 
        /**