wikimedia/mediawiki-core

View on GitHub
includes/parser/CoreParserFunctions.php

Summary

Maintainability
F
1 wk
Test Coverage

File CoreParserFunctions.php has 1027 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Parser functions provided by MediaWiki core
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/parser/CoreParserFunctions.php - About 2 days to fix

    CoreParserFunctions has 83 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CoreParserFunctions {
        /** @var int Assume that no output will later be saved this many seconds after parsing */
        private const MAX_TTS = 900;
    
        /**
    Severity: Major
    Found in includes/parser/CoreParserFunctions.php - About 1 day to fix

      Method register has 72 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function register( Parser $parser, ServiceOptions $options ) {
              $options->assertRequiredOptions( self::REGISTER_OPTIONS );
              $allowDisplayTitle = $options->get( MainConfigNames::AllowDisplayTitle );
              $allowSlowParserFunctions = $options->get( MainConfigNames::AllowSlowParserFunctions );
      
      
      Severity: Major
      Found in includes/parser/CoreParserFunctions.php - About 2 hrs to fix

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

            public static function revisionid( $parser, $title = null ) {
                $t = self::makeTitle( $parser, $title );
                if ( $t === null || $t->isExternal() ) {
                    return '';
                }
        Severity: Minor
        Found in includes/parser/CoreParserFunctions.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

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

            public static function displaytitle( $parser, $text = '', $uarg = '' ) {
                $restrictDisplayTitle = MediaWikiServices::getInstance()->getMainConfig()
                    ->get( MainConfigNames::RestrictDisplayTitle );
        
                static $magicWords = null;
        Severity: Minor
        Found in includes/parser/CoreParserFunctions.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 displaytitle has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function displaytitle( $parser, $text = '', $uarg = '' ) {
                $restrictDisplayTitle = MediaWikiServices::getInstance()->getMainConfig()
                    ->get( MainConfigNames::RestrictDisplayTitle );
        
                static $magicWords = null;
        Severity: Major
        Found in includes/parser/CoreParserFunctions.php - About 2 hrs to fix

          Function getCachedRevisionObject has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              private static function getCachedRevisionObject( $parser, $title, $vary ) {
                  if ( !$title ) {
                      return null;
                  }
          
          
          Severity: Minor
          Found in includes/parser/CoreParserFunctions.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 pagesincategory has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function pagesincategory( $parser, $name = '', $arg1 = '', $arg2 = '' ) {
                  static $magicWords = null;
                  if ( $magicWords === null ) {
                      $magicWords = $parser->getMagicWordFactory()->newArray( [
                          'pagesincategory_all',
          Severity: Minor
          Found in includes/parser/CoreParserFunctions.php - About 1 hr to fix

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

                public static function tagObj( $parser, $frame, $args ) {
                    if ( !count( $args ) ) {
                        return '';
                    }
                    $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
            Severity: Minor
            Found in includes/parser/CoreParserFunctions.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 getCachedRevisionObject has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static function getCachedRevisionObject( $parser, $title, $vary ) {
                    if ( !$title ) {
                        return null;
                    }
            
            
            Severity: Minor
            Found in includes/parser/CoreParserFunctions.php - About 1 hr to fix

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

                  public static function tagObj( $parser, $frame, $args ) {
                      if ( !count( $args ) ) {
                          return '';
                      }
                      $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
              Severity: Minor
              Found in includes/parser/CoreParserFunctions.php - About 1 hr to fix

                Method revisionid has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function revisionid( $parser, $title = null ) {
                        $t = self::makeTitle( $parser, $title );
                        if ( $t === null || $t->isExternal() ) {
                            return '';
                        }
                Severity: Minor
                Found in includes/parser/CoreParserFunctions.php - About 1 hr to fix

                  Function filepath has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) {
                          $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
                  
                          if ( $argA == 'nowiki' ) {
                              // {{filepath: | option [| size] }}
                  Severity: Minor
                  Found in includes/parser/CoreParserFunctions.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 pageid has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function pageid( $parser, $title = null ) {
                          $t = self::makeTitle( $parser, $title );
                          if ( !$t ) {
                              return '';
                          } elseif ( !$t->canExist() || $t->isExternal() ) {
                  Severity: Minor
                  Found in includes/parser/CoreParserFunctions.php - About 1 hr to fix

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

                        private static function getRevisionTimestampSubstring(
                            Parser $parser,
                            Title $title,
                            int $start,
                            int $len,
                    Severity: Minor
                    Found in includes/parser/CoreParserFunctions.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 pagesincategory has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function pagesincategory( $parser, $name = '', $arg1 = '', $arg2 = '' ) {
                            static $magicWords = null;
                            if ( $magicWords === null ) {
                                $magicWords = $parser->getMagicWordFactory()->newArray( [
                                    'pagesincategory_all',
                    Severity: Minor
                    Found in includes/parser/CoreParserFunctions.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

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

                        public static function pageid( $parser, $title = null ) {
                            $t = self::makeTitle( $parser, $title );
                            if ( !$t ) {
                                return '';
                            } elseif ( !$t->canExist() || $t->isExternal() ) {
                    Severity: Minor
                    Found in includes/parser/CoreParserFunctions.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 getRevisionTimestampSubstring has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                            Parser $parser,
                            Title $title,
                            int $start,
                            int $len,
                            int $mtts
                    Severity: Minor
                    Found in includes/parser/CoreParserFunctions.php - About 35 mins to fix

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

                              $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT
                      Severity: Minor
                      Found in includes/parser/CoreParserFunctions.php - About 35 mins to fix

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

                            public static function urlFunction( $func, $s = '', $arg = null ) {
                                # Due to order of execution of a lot of bits, the values might be encoded
                                # before arriving here; if that's true, then the title can't be created
                                # and the variable will fail. If we can't get a decent title from the first
                                # attempt, url-decode and try for a second.
                        Severity: Minor
                        Found in includes/parser/CoreParserFunctions.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 null;
                        Severity: Major
                        Found in includes/parser/CoreParserFunctions.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return $rev ? $rev->getId() : '';
                          Severity: Major
                          Found in includes/parser/CoreParserFunctions.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return $id;
                            Severity: Major
                            Found in includes/parser/CoreParserFunctions.php - About 30 mins to fix

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

                                  public static function defaultsort( $parser, $text, $uarg = '' ) {
                                      static $magicWords = null;
                                      if ( $magicWords === null ) {
                                          $magicWords = $parser->getMagicWordFactory()->newArray(
                                              [ 'defaultsort_noerror', 'defaultsort_noreplace' ] );
                              Severity: Minor
                              Found in includes/parser/CoreParserFunctions.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 gender has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public static function gender( $parser, $username, ...$forms ) {
                                      // Some shortcuts to avoid loading user data unnecessarily
                                      if ( count( $forms ) === 0 ) {
                                          return '';
                                      } elseif ( count( $forms ) === 1 ) {
                              Severity: Minor
                              Found in includes/parser/CoreParserFunctions.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 formatRaw has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public static function formatRaw(
                                      $num, $raw, $language, MagicWordFactory $magicWordFactory = null
                                  ) {
                                      if ( $raw !== null && $raw !== '' ) {
                                          if ( !$magicWordFactory ) {
                              Severity: Minor
                              Found in includes/parser/CoreParserFunctions.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

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  public static function revisionmonth1( $parser, $title = null ) {
                                      $t = self::makeTitle( $parser, $title );
                                      if ( $t === null || $t->isExternal() ) {
                                          return '';
                                      }
                              Severity: Minor
                              Found in includes/parser/CoreParserFunctions.php and 1 other location - About 30 mins to fix
                              includes/parser/CoreParserFunctions.php on lines 1459..1467

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 90.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  public static function revisionday( $parser, $title = null ) {
                                      $t = self::makeTitle( $parser, $title );
                                      if ( $t === null || $t->isExternal() ) {
                                          return '';
                                      }
                              Severity: Minor
                              Found in includes/parser/CoreParserFunctions.php and 1 other location - About 30 mins to fix
                              includes/parser/CoreParserFunctions.php on lines 1510..1518

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 90.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              There are no issues that match your filters.

                              Category
                              Status