From 073abe3e127a439498b3d82a736782e7ee798699 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Wed, 1 Jan 2014 19:56:08 +0100 Subject: [PATCH] No variable assignment on return statement 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 --- includes/EditPage.php | 6 +-- includes/Linker.php | 3 +- includes/Title.php | 41 +++++++++++-------- includes/WikiFilePage.php | 6 ++- includes/WikiPage.php | 6 ++- includes/logging/DeleteLogFormatter.php | 9 ++-- includes/logging/LogFormatter.php | 6 ++- includes/resourceloader/ResourceLoader.php | 8 ++-- .../ResourceLoaderFileModule.php | 3 +- .../ResourceLoaderStartUpModule.php | 3 +- .../ResourceLoaderUserCSSPrefsModule.php | 8 ++-- .../ResourceLoaderUserOptionsModule.php | 8 ++-- includes/upload/UploadBase.php | 21 ++++++---- languages/LanguageConverter.php | 6 ++- 14 files changed, 81 insertions(+), 53 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index f86cae46f4..ba493787b2 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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; } /** diff --git a/includes/Linker.php b/includes/Linker.php index 27f8ab4514..9e489e71b4 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -2137,7 +2137,8 @@ class Linker { } wfProfileOut( __METHOD__ ); - return self::$accesskeycache[$name] = $accesskey; + self::$accesskeycache[$name] = $accesskey; + return self::$accesskeycache[$name]; } /** diff --git a/includes/Title.php b/includes/Title.php index 5ab9e94d6d..1c63e14217 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ) { diff --git a/includes/WikiFilePage.php b/includes/WikiFilePage.php index 2b192b0f06..817f0fa7eb 100644 --- a/includes/WikiFilePage.php +++ b/includes/WikiFilePage.php @@ -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 diff --git a/includes/WikiPage.php b/includes/WikiPage.php index d4acb6f4fd..f0a58d3f5c 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -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; } /** diff --git a/includes/logging/DeleteLogFormatter.php b/includes/logging/DeleteLogFormatter.php index d761a8720f..b658ac1ec6 100644 --- a/includes/logging/DeleteLogFormatter.php +++ b/includes/logging/DeleteLogFormatter.php @@ -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 ) { diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 084a4b29c2..9e7f056f08 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -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(); diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 3b072f9a37..08b1ac1314 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -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; } /** diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 43330dabb4..eaff86feff 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -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' ); diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 93c5d1b99b..d0c3068c53 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -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 */ diff --git a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php index aafe432383..a9d10766a0 100644 --- a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php +++ b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php @@ -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]; } /** diff --git a/includes/resourceloader/ResourceLoaderUserOptionsModule.php b/includes/resourceloader/ResourceLoaderUserOptionsModule.php index 1df8c56e47..3686bea5ec 100644 --- a/includes/resourceloader/ResourceLoaderUserOptionsModule.php +++ b/includes/resourceloader/ResourceLoaderUserOptionsModule.php @@ -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]; } /** diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index a6c34212a8..3d2b3f44e6 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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; } /** diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index cdaab2ce7b..cec9ddb5db 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -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; } /** -- 2.20.1