wikimedia/mediawiki-core

View on GitHub
includes/page/Article.php

Summary

Maintainability
F
1 wk
Test Coverage

File Article.php has 1328 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Major
Found in includes/page/Article.php - About 3 days to fix

    Article has 48 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Article implements Page {
        use ProtectedHookAccessorTrait;
        use NonSerializableTrait;
    
        /**
    Severity: Minor
    Found in includes/page/Article.php - About 6 hrs to fix

      Method setOldSubtitle has 135 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function setOldSubtitle( $oldid = 0 ) {
              if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) {
                  return;
              }
      
      
      Severity: Major
      Found in includes/page/Article.php - About 5 hrs to fix

        Method generateContentOutput has 124 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function generateContentOutput(
                Authority $performer,
                ParserOptions $parserOptions,
                int $oldid,
                OutputPage $outputPage,
        Severity: Major
        Found in includes/page/Article.php - About 4 hrs to fix

          Method showMissingArticle has 124 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function showMissingArticle() {
                  $context = $this->getContext();
                  $send404Code = $context->getConfig()->get( MainConfigNames::Send404Code );
          
                  $outputPage = $context->getOutput();
          Severity: Major
          Found in includes/page/Article.php - About 4 hrs to fix

            Method view has 115 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function view() {
                    $context = $this->getContext();
                    $useFileCache = $context->getConfig()->get( MainConfigNames::UseFileCache );
            
                    # Get variables from query string
            Severity: Major
            Found in includes/page/Article.php - About 4 hrs to fix

              Method showPatrolFooter has 113 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function showPatrolFooter() {
                      $context = $this->getContext();
                      $mainConfig = $context->getConfig();
                      $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
                      $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
              Severity: Major
              Found in includes/page/Article.php - About 4 hrs to fix

                Function getOldIDFromRequest has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getOldIDFromRequest() {
                        $this->mRedirectUrl = false;
                
                        $request = $this->getContext()->getRequest();
                        $oldid = $request->getIntOrNull( 'oldid' );
                Severity: Minor
                Found in includes/page/Article.php - About 4 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function generateContentOutput has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function generateContentOutput(
                        Authority $performer,
                        ParserOptions $parserOptions,
                        int $oldid,
                        OutputPage $outputPage,
                Severity: Minor
                Found in includes/page/Article.php - About 3 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function showPatrolFooter has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function showPatrolFooter() {
                        $context = $this->getContext();
                        $mainConfig = $context->getConfig();
                        $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
                        $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
                Severity: Minor
                Found in includes/page/Article.php - About 3 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function showMissingArticle has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function showMissingArticle() {
                        $context = $this->getContext();
                        $send404Code = $context->getConfig()->get( MainConfigNames::Send404Code );
                
                        $outputPage = $context->getOutput();
                Severity: Minor
                Found in includes/page/Article.php - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method getRobotPolicy has 68 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getRobotPolicy( $action, ParserOutput $pOutput = null ) {
                        $context = $this->getContext();
                        $mainConfig = $context->getConfig();
                        $articleRobotPolicies = $mainConfig->get( MainConfigNames::ArticleRobotPolicies );
                        $namespaceRobotPolicies = $mainConfig->get( MainConfigNames::NamespaceRobotPolicies );
                Severity: Major
                Found in includes/page/Article.php - About 2 hrs to fix

                  Function view has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function view() {
                          $context = $this->getContext();
                          $useFileCache = $context->getConfig()->get( MainConfigNames::UseFileCache );
                  
                          # Get variables from query string
                  Severity: Minor
                  Found in includes/page/Article.php - About 2 hrs to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method showDiffPage has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function showDiffPage() {
                          $context = $this->getContext();
                          $outputPage = $context->getOutput();
                          $outputPage->addBodyClasses( 'mw-article-diff' );
                          $request = $context->getRequest();
                  Severity: Major
                  Found in includes/page/Article.php - About 2 hrs to fix

                    Method getOldIDFromRequest has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function getOldIDFromRequest() {
                            $this->mRedirectUrl = false;
                    
                            $request = $this->getContext()->getRequest();
                            $oldid = $request->getIntOrNull( 'oldid' );
                    Severity: Minor
                    Found in includes/page/Article.php - About 2 hrs to fix

                      Function fetchRevisionRecord has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function fetchRevisionRecord() {
                              if ( $this->fetchResult ) {
                                  return $this->mRevisionRecord;
                              }
                      
                      
                      Severity: Minor
                      Found in includes/page/Article.php - About 1 hr to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Method showRedirectedFromHeader has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function showRedirectedFromHeader() {
                              $context = $this->getContext();
                              $redirectSources = $context->getConfig()->get( MainConfigNames::RedirectSources );
                              $outputPage = $context->getOutput();
                              $request = $context->getRequest();
                      Severity: Minor
                      Found in includes/page/Article.php - About 1 hr to fix

                        Function getRobotPolicy has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function getRobotPolicy( $action, ParserOutput $pOutput = null ) {
                                $context = $this->getContext();
                                $mainConfig = $context->getConfig();
                                $articleRobotPolicies = $mainConfig->get( MainConfigNames::ArticleRobotPolicies );
                                $namespaceRobotPolicies = $mainConfig->get( MainConfigNames::NamespaceRobotPolicies );
                        Severity: Minor
                        Found in includes/page/Article.php - About 1 hr to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Method showDeletedRevisionHeader has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function showDeletedRevisionHeader() {
                                if ( !$this->mRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
                                    // Not deleted
                                    return true;
                                }
                        Severity: Minor
                        Found in includes/page/Article.php - About 1 hr to fix

                          Method fetchRevisionRecord has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function fetchRevisionRecord() {
                                  if ( $this->fetchResult ) {
                                      return $this->mRevisionRecord;
                                  }
                          
                          
                          Severity: Minor
                          Found in includes/page/Article.php - About 1 hr to fix

                            Method doOutputFromRenderStatus has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                private function doOutputFromRenderStatus(
                                    RevisionRecord $rev,
                                    Status $renderStatus,
                                    OutputPage $outputPage,
                                    array $textOptions
                            Severity: Minor
                            Found in includes/page/Article.php - About 1 hr to fix

                              Function showRedirectedFromHeader has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function showRedirectedFromHeader() {
                                      $context = $this->getContext();
                                      $redirectSources = $context->getConfig()->get( MainConfigNames::RedirectSources );
                                      $outputPage = $context->getOutput();
                                      $request = $context->getRequest();
                              Severity: Minor
                              Found in includes/page/Article.php - About 45 mins to fix

                              Cognitive Complexity

                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                              A method's cognitive complexity is based on a few simple rules:

                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                              • Code is considered more complex for each "break in the linear flow of the code"
                              • Code is considered more complex when "flow breaking structures are nested"

                              Further reading

                              Consider simplifying this complex logical expression.
                              Open

                                          if ( !( $user && $user->isRegistered() ) && !$ip ) {
                                              // User does not exist
                                              $outputPage->addHTML( Html::warningBox(
                                                  $context->msg( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) )->parse(),
                                                  'mw-userpage-userdoesnotexist'
                              Severity: Major
                              Found in includes/page/Article.php - About 40 mins to fix

                                Method generateContentOutput has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                        Authority $performer,
                                        ParserOptions $parserOptions,
                                        int $oldid,
                                        OutputPage $outputPage,
                                        array $textOptions
                                Severity: Minor
                                Found in includes/page/Article.php - About 35 mins to fix

                                  Function setOldSubtitle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function setOldSubtitle( $oldid = 0 ) {
                                          if ( !$this->getHookRunner()->onDisplayOldSubtitle( $this, $oldid ) ) {
                                              return;
                                          }
                                  
                                  
                                  Severity: Minor
                                  Found in includes/page/Article.php - About 35 mins to fix

                                  Cognitive Complexity

                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                  A method's cognitive complexity is based on a few simple rules:

                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                  • Code is considered more complex for each "break in the linear flow of the code"
                                  • Code is considered more complex when "flow breaking structures are nested"

                                  Further reading

                                  Function formatRobotPolicy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public static function formatRobotPolicy( $policy ) {
                                          if ( is_array( $policy ) ) {
                                              return $policy;
                                          } elseif ( !$policy ) {
                                              return [];
                                  Severity: Minor
                                  Found in includes/page/Article.php - About 35 mins to fix

                                  Cognitive Complexity

                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                  A method's cognitive complexity is based on a few simple rules:

                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                  • Code is considered more complex for each "break in the linear flow of the code"
                                  • Code is considered more complex when "flow breaking structures are nested"

                                  Further reading

                                  Avoid too many return statements within this method.
                                  Open

                                          return true;
                                  Severity: Major
                                  Found in includes/page/Article.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                        return true;
                                    Severity: Major
                                    Found in includes/page/Article.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                              return $this->mRevisionRecord;
                                      Severity: Major
                                      Found in includes/page/Article.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return true;
                                        Severity: Major
                                        Found in includes/page/Article.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return true;
                                          Severity: Major
                                          Found in includes/page/Article.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                        return false;
                                            Severity: Major
                                            Found in includes/page/Article.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return false;
                                              Severity: Major
                                              Found in includes/page/Article.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                return false; // skip all further output to OutputPage
                                                Severity: Major
                                                Found in includes/page/Article.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                              return true;
                                                  Severity: Major
                                                  Found in includes/page/Article.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                            return $policy;
                                                    Severity: Major
                                                    Found in includes/page/Article.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return false;
                                                      Severity: Major
                                                      Found in includes/page/Article.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                    return false;
                                                        Severity: Major
                                                        Found in includes/page/Article.php - About 30 mins to fix

                                                          Function showDiffPage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                              protected function showDiffPage() {
                                                                  $context = $this->getContext();
                                                                  $outputPage = $context->getOutput();
                                                                  $outputPage->addBodyClasses( 'mw-article-diff' );
                                                                  $request = $context->getRequest();
                                                          Severity: Minor
                                                          Found in includes/page/Article.php - About 25 mins to fix

                                                          Cognitive Complexity

                                                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                          A method's cognitive complexity is based on a few simple rules:

                                                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                          • Code is considered more complex for each "break in the linear flow of the code"
                                                          • Code is considered more complex when "flow breaking structures are nested"

                                                          Further reading

                                                          Function tryFileCache has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                              protected function tryFileCache() {
                                                                  static $called = false;
                                                          
                                                                  if ( $called ) {
                                                                      wfDebug( "Article::tryFileCache(): called twice!?" );
                                                          Severity: Minor
                                                          Found in includes/page/Article.php - About 25 mins to fix

                                                          Cognitive Complexity

                                                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                          A method's cognitive complexity is based on a few simple rules:

                                                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                          • Code is considered more complex for each "break in the linear flow of the code"
                                                          • Code is considered more complex when "flow breaking structures are nested"

                                                          Further reading

                                                          There are no issues that match your filters.

                                                          Category
                                                          Status