Linker: Simplify return paths
authorFomafix <fomafix@googlemail.com>
Thu, 3 Jan 2019 10:13:19 +0000 (11:13 +0100)
committerFomafix <fomafix@googlemail.com>
Thu, 17 Jan 2019 11:25:39 +0000 (12:25 +0100)
* Avoid else after return.
* Use early-return pattern.

Change-Id: I059e233d019dbc2233756776dfa09f8f2fdb2df7

includes/Linker.php

index 89a41dc..d1434f8 100644 (file)
@@ -958,23 +958,23 @@ class Linker {
 
                Hooks::run( 'UserToolLinksEdit', [ $userId, $userText, &$items ] );
 
-               if ( $items ) {
-                       if ( $useParentheses ) {
-                               return wfMessage( 'word-separator' )->escaped()
-                                       . '<span class="mw-usertoollinks">'
-                                       . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
-                                       . '</span>';
-                       } else {
-                               $tools = [];
-                               foreach ( $items as $tool ) {
-                                       $tools[] = Html::rawElement( 'span', [], $tool );
-                               }
-                               return ' <span class="mw-usertoollinks mw-changeslist-links">' .
-                                       implode( ' ', $tools ) . '</span>';
-                       }
-               } else {
+               if ( !$items ) {
                        return '';
                }
+
+               if ( $useParentheses ) {
+                       return wfMessage( 'word-separator' )->escaped()
+                               . '<span class="mw-usertoollinks">'
+                               . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
+                               . '</span>';
+               }
+
+               $tools = [];
+               foreach ( $items as $tool ) {
+                       $tools[] = Html::rawElement( 'span', [], $tool );
+               }
+               return ' <span class="mw-usertoollinks mw-changeslist-links">' .
+                       implode( ' ', $tools ) . '</span>';
        }
 
        /**
@@ -1463,16 +1463,15 @@ class Linker {
                // compatibility, acc. to brion -ævar
                if ( $comment == '' || $comment == '*' ) {
                        return '';
+               }
+               $formatted = self::formatComment( $comment, $title, $local, $wikiId );
+               if ( $useParentheses ) {
+                       $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
+                       $classNames = 'comment';
                } else {
-                       $formatted = self::formatComment( $comment, $title, $local, $wikiId );
-                       if ( $useParentheses ) {
-                               $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
-                               $classNames = 'comment';
-                       } else {
-                               $classNames = 'comment comment--without-parentheses';
-                       }
-                       return " <span class=\"$classNames\">$formatted</span>";
+                       $classNames = 'comment comment--without-parentheses';
                }
+               return " <span class=\"$classNames\">$formatted</span>";
        }
 
        /**
@@ -2089,27 +2088,26 @@ class Linker {
 
                if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
                        return self::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
+               }
+               if ( $rev->getId() ) {
+                       // RevDelete links using revision ID are stable across
+                       // page deletion and undeletion; use when possible.
+                       $query = [
+                               'type' => 'revision',
+                               'target' => $title->getPrefixedDBkey(),
+                               'ids' => $rev->getId()
+                       ];
                } else {
-                       if ( $rev->getId() ) {
-                               // RevDelete links using revision ID are stable across
-                               // page deletion and undeletion; use when possible.
-                               $query = [
-                                       'type' => 'revision',
-                                       'target' => $title->getPrefixedDBkey(),
-                                       'ids' => $rev->getId()
-                               ];
-                       } else {
-                               // Older deleted entries didn't save a revision ID.
-                               // We have to refer to these by timestamp, ick!
-                               $query = [
-                                       'type' => 'archive',
-                                       'target' => $title->getPrefixedDBkey(),
-                                       'ids' => $rev->getTimestamp()
-                               ];
-                       }
-                       return self::revDeleteLink( $query,
-                               $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
+                       // Older deleted entries didn't save a revision ID.
+                       // We have to refer to these by timestamp, ick!
+                       $query = [
+                               'type' => 'archive',
+                               'target' => $title->getPrefixedDBkey(),
+                               'ids' => $rev->getTimestamp()
+                       ];
                }
+               return self::revDeleteLink( $query,
+                       $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
        }
 
        /**