wikimedia/mediawiki-core

View on GitHub
includes/title/Title.php

Summary

Maintainability
F
1 wk
Test Coverage

File Title.php has 1901 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Representation of a title within MediaWiki.
 *
 * See Title.md
Severity: Major
Found in includes/title/Title.php - About 5 days to fix

    Title has 168 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Title implements LinkTarget, PageIdentity {
        use WikiAwareEntityTrait;
        use LinkTargetTrait;
    
        /** @var MapCacheLRU|null */
    Severity: Major
    Found in includes/title/Title.php - About 3 days to fix

      Function getLocalURL has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getLocalURL( $query = '' ) {
              global $wgArticlePath, $wgScript, $wgMainPageIsDomainRoot;
      
              $query = is_array( $query ) ? wfArrayToCgi( $query ) : $query;
      
      
      Severity: Minor
      Found in includes/title/Title.php - About 6 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 convertByteClassToUnicodeClass has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function convertByteClassToUnicodeClass( $byteClass ) {
              $length = strlen( $byteClass );
              // Input token queue
              $x0 = $x1 = $x2 = '';
              // Decoded queue
      Severity: Minor
      Found in includes/title/Title.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

      Method convertByteClassToUnicodeClass has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function convertByteClassToUnicodeClass( $byteClass ) {
              $length = strlen( $byteClass );
              // Input token queue
              $x0 = $x1 = $x2 = '';
              // Decoded queue
      Severity: Major
      Found in includes/title/Title.php - About 2 hrs to fix

        Method getLocalURL has 66 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getLocalURL( $query = '' ) {
                global $wgArticlePath, $wgScript, $wgMainPageIsDomainRoot;
        
                $query = is_array( $query ) ? wfArrayToCgi( $query ) : $query;
        
        
        Severity: Major
        Found in includes/title/Title.php - About 2 hrs to fix

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

              public function loadFromRow( $row ) {
                  if ( $row ) { // page found
                      if ( isset( $row->page_id ) ) {
                          $this->mArticleID = (int)$row->page_id;
                      }
          Severity: Minor
          Found in includes/title/Title.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 getLinksFrom has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
                  $id = $this->getArticleID();
          
                  # If the page doesn't exist; there can't be any link from this page
                  if ( !$id ) {
          Severity: Minor
          Found in includes/title/Title.php - About 1 hr to fix

            Method getEditNotices has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getEditNotices( $oldid = 0 ) {
                    $notices = [];
            
                    $editnotice_base = 'editnotice-' . $this->mNamespace;
                    // Optional notice for the entire namespace
            Severity: Minor
            Found in includes/title/Title.php - About 1 hr to fix

              Method getLinksTo has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
                      if ( count( $options ) > 0 ) {
                          $db = $this->getDbProvider()->getPrimaryDatabase();
                      } else {
                          $db = $this->getDbProvider()->getReplicaDatabase();
              Severity: Minor
              Found in includes/title/Title.php - About 1 hr to fix

                Method purgeExpiredRestrictions has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function purgeExpiredRestrictions() {
                        if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) {
                            return;
                        }
                
                
                Severity: Minor
                Found in includes/title/Title.php - About 1 hr to fix

                  Function getParentCategoryTree has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getParentCategoryTree( $children = [] ) {
                          $stack = [];
                          $parents = $this->getParentCategories();
                  
                          if ( $parents ) {
                  Severity: Minor
                  Found in includes/title/Title.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 invalidateCache has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function invalidateCache( $purgeTime = null ) {
                          if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) {
                              return false;
                          }
                          if ( $this->mArticleID === 0 ) {
                  Severity: Minor
                  Found in includes/title/Title.php - About 1 hr to fix

                    Method loadFromRow has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function loadFromRow( $row ) {
                            if ( $row ) { // page found
                                if ( isset( $row->page_id ) ) {
                                    $this->mArticleID = (int)$row->page_id;
                                }
                    Severity: Minor
                    Found in includes/title/Title.php - About 1 hr to fix

                      Function getLinksTo has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function getLinksTo( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
                              if ( count( $options ) > 0 ) {
                                  $db = $this->getDbProvider()->getPrimaryDatabase();
                              } else {
                                  $db = $this->getDbProvider()->getReplicaDatabase();
                      Severity: Minor
                      Found in includes/title/Title.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

                      Function getEditNotices has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function getEditNotices( $oldid = 0 ) {
                              $notices = [];
                      
                              $editnotice_base = 'editnotice-' . $this->mNamespace;
                              // Optional notice for the entire namespace
                      Severity: Minor
                      Found in includes/title/Title.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

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

                          public function getNsText() {
                              if ( $this->isExternal() ) {
                                  // This probably shouldn't even happen, except for interwiki transclusion.
                                  // If possible, use the canonical name for the foreign namespace.
                                  if ( $this->mNamespace === NS_MAIN ) {
                      Severity: Minor
                      Found in includes/title/Title.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

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

                          public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
                              $canonicalNamespace = false
                      Severity: Minor
                      Found in includes/title/Title.php - About 35 mins to fix

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

                            public function isValidRedirectTarget() {
                                global $wgInvalidRedirectTargets;
                        
                                if ( $this->isSpecialPage() ) {
                                    // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
                        Severity: Minor
                        Found in includes/title/Title.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 getLinksFrom has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function getLinksFrom( $options = [], $table = 'pagelinks', $prefix = 'pl' ) {
                                $id = $this->getArticleID();
                        
                                # If the page doesn't exist; there can't be any link from this page
                                if ( !$id ) {
                        Severity: Minor
                        Found in includes/title/Title.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 $this->mDbkeyform == '';
                        Severity: Major
                        Found in includes/title/Title.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

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

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

                                              return $this->hasSourceText() !== false;
                              Severity: Major
                              Found in includes/title/Title.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return $pageLang;
                                Severity: Major
                                Found in includes/title/Title.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return $this->isValid();
                                  Severity: Major
                                  Found in includes/title/Title.php - About 30 mins to fix

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

                                        public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
                                            if ( is_object( $text ) ) {
                                                throw new InvalidArgumentException( '$text must be a string, given an object' );
                                            } elseif ( $text === null ) {
                                                // Legacy code relies on MalformedTitleException being thrown in this case
                                    Severity: Minor
                                    Found in includes/title/Title.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 getPageViewLanguage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public function getPageViewLanguage() {
                                            $services = MediaWikiServices::getInstance();
                                    
                                            if ( $this->isSpecialPage() ) {
                                                // If the user chooses a variant, the content is actually
                                    Severity: Minor
                                    Found in includes/title/Title.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 fixSpecialName has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public function fixSpecialName() {
                                            if ( $this->isSpecialPage() ) {
                                                $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory();
                                                [ $canonicalName, $par ] = $spFactory->resolveAlias( $this->mDbkeyform );
                                                if ( $canonicalName ) {
                                    Severity: Minor
                                    Found in includes/title/Title.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 getContentModel has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public function getContentModel( $flags = 0 ) {
                                            if ( $this->mForcedContentModel ) {
                                                if ( !$this->mContentModel ) {
                                                    throw new RuntimeException( 'Got out of sync; an empty model is being forced' );
                                                }
                                    Severity: Minor
                                    Found in includes/title/Title.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 getFieldFromPageStore has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private function getFieldFromPageStore( $field, $flags ) {
                                            $pageStore = MediaWikiServices::getInstance()->getPageStore();
                                    
                                            if ( !in_array( $field, $pageStore->getSelectFields(), true ) ) {
                                                throw new InvalidArgumentException( "Unknown field: $field" );
                                    Severity: Minor
                                    Found in includes/title/Title.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