wikimedia/mediawiki-core

View on GitHub
includes/language/LanguageConverter.php

Summary

Maintainability
F
1 wk
Test Coverage

File LanguageConverter.php has 773 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/language/LanguageConverter.php - About 1 day to fix

    LanguageConverter has 49 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class LanguageConverter implements ILanguageConverter {
        use DeprecationHelper;
    
        /**
         * languages supporting variants
    Severity: Minor
    Found in includes/language/LanguageConverter.php - About 6 hrs to fix

      Function parseCachedTable has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

          private function parseCachedTable( $code, $subpage = '', $recursive = true ) {
              static $parsed = [];
      
              $key = 'Conversiontable/' . $code;
              if ( $subpage ) {
      Severity: Minor
      Found in includes/language/LanguageConverter.php - About 5 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 autoConvert has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

          public function autoConvert( $text, $toVariant = false ) {
              $this->loadTables();
      
              if ( !$toVariant ) {
                  $toVariant = $this->getPreferredVariant();
      Severity: Minor
      Found in includes/language/LanguageConverter.php - About 5 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 autoConvert has 90 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function autoConvert( $text, $toVariant = false ) {
              $this->loadTables();
      
              if ( !$toVariant ) {
                  $toVariant = $this->getPreferredVariant();
      Severity: Major
      Found in includes/language/LanguageConverter.php - About 3 hrs to fix

        Method parseCachedTable has 84 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function parseCachedTable( $code, $subpage = '', $recursive = true ) {
                static $parsed = [];
        
                $key = 'Conversiontable/' . $code;
                if ( $subpage ) {
        Severity: Major
        Found in includes/language/LanguageConverter.php - About 3 hrs to fix

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

              public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
                  # If the article has already existed, there is no need to
                  # check it again. Otherwise it may cause a fault.
                  if ( $nt instanceof LinkTarget ) {
                      $nt = Title::castFromLinkTarget( $nt );
          Severity: Minor
          Found in includes/language/LanguageConverter.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

          Method findVariantLink has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
                  # If the article has already existed, there is no need to
                  # check it again. Otherwise it may cause a fault.
                  if ( $nt instanceof LinkTarget ) {
                      $nt = Title::castFromLinkTarget( $nt );
          Severity: Major
          Found in includes/language/LanguageConverter.php - About 2 hrs to fix

            Function getHeaderVariant has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function getHeaderVariant() {
                    global $wgRequest;
            
                    if ( $this->mHeaderVariant ) {
                        return $this->mHeaderVariant;
            Severity: Minor
            Found in includes/language/LanguageConverter.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 recursiveConvertRule has 48 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
                    // Quick check (no function calls)
                    if ( $text[$startPos] !== '-' || $text[$startPos + 1] !== '{' ) {
                        throw new InvalidArgumentException( __METHOD__ . ': invalid input string' );
                    }
            Severity: Minor
            Found in includes/language/LanguageConverter.php - About 1 hr to fix

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

                  protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
                      // Quick check (no function calls)
                      if ( $text[$startPos] !== '-' || $text[$startPos + 1] !== '{' ) {
                          throw new InvalidArgumentException( __METHOD__ . ': invalid input string' );
                      }
              Severity: Minor
              Found in includes/language/LanguageConverter.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 getHeaderVariant has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function getHeaderVariant() {
                      global $wgRequest;
              
                      if ( $this->mHeaderVariant ) {
                          return $this->mHeaderVariant;
              Severity: Minor
              Found in includes/language/LanguageConverter.php - About 1 hr to fix

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

                    protected function applyManualConv( ConverterRule $convRule ) {
                        // Use syntax -{T|zh-cn:TitleCN; zh-tw:TitleTw}- to custom
                        // title conversion.
                        // T26072: $mConvRuleTitle was overwritten by other manual
                        // rule(s) not for title, this breaks the title conversion.
                Severity: Minor
                Found in includes/language/LanguageConverter.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 recursiveConvertTopLevel has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) {
                        $startPos = 0;
                        $out = '';
                        $length = strlen( $text );
                        $shouldConvert = !$this->guessVariant( $text, $variant );
                Severity: Minor
                Found in includes/language/LanguageConverter.php - About 1 hr to fix

                  Function getUserVariant has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function getUserVariant( User $user ) {
                          // This should only be called within the class after the user is known to be
                          // safe to load and logged in, but check just in case.
                          if ( !$user->isSafeToLoad() ) {
                              return null;
                  Severity: Minor
                  Found in includes/language/LanguageConverter.php - About 55 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 getVarSeparatorPattern has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getVarSeparatorPattern() {
                          if ( $this->mVarSeparatorPattern === null ) {
                              // varsep_pattern for preg_split:
                              // The text should be split by ";" only if a valid variant
                              // name exists after the markup.
                  Severity: Minor
                  Found in includes/language/LanguageConverter.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 ( $disableLinkConversion ||
                              ( !$ignoreOtherCond &&
                                  ( $isredir == 'no'
                                      || $action == 'edit'
                                      || $action == 'submit'
                  Severity: Major
                  Found in includes/language/LanguageConverter.php - About 40 mins to fix

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

                        public function getPreferredVariant() {
                            $req = $this->getURLVariant();
                    
                            $services = MediaWikiServices::getInstance();
                            ( new HookRunner( $services->getHookContainer() ) )->onGetLangPreferredVariant( $req );
                    Severity: Minor
                    Found in includes/language/LanguageConverter.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

                    There are no issues that match your filters.

                    Category
                    Status