wikimedia/mediawiki-core

View on GitHub
includes/parser/Parser.php

Summary

Maintainability
F
1 mo
Test Coverage

File Parser.php has 4048 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * PHP parser that converts wiki markup to HTML.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/parser/Parser.php - About 1 wk to fix

    Parser has 147 functions (exceeds 20 allowed). Consider refactoring.
    Open

    #[\AllowDynamicProperties]
    class Parser {
    
        # Flags for Parser::setFunctionHook
        public const SFH_NO_HASH = 1;
    Severity: Major
    Found in includes/parser/Parser.php - About 2 days to fix

      Function braceSubstitution has a Cognitive Complexity of 142 (exceeds 5 allowed). Consider refactoring.
      Open

          public function braceSubstitution( array $piece, PPFrame $frame ) {
              // Flags
      
              // $text has been filled
              $found = false;
      Severity: Minor
      Found in includes/parser/Parser.php - About 2 days 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 handleInternalLinks2 has a Cognitive Complexity of 118 (exceeds 5 allowed). Consider refactoring.
      Open

          private function handleInternalLinks2( &$s ) {
              static $tc = false, $e1, $e1_img;
              # the % is needed to support urlencoded titles as well
              if ( !$tc ) {
                  $tc = Title::legalChars() . '#%';
      Severity: Minor
      Found in includes/parser/Parser.php - About 2 days 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 braceSubstitution has 310 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function braceSubstitution( array $piece, PPFrame $frame ) {
              // Flags
      
              // $text has been filled
              $found = false;
      Severity: Major
      Found in includes/parser/Parser.php - About 1 day to fix

        Function handleTables has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
        Open

            private function handleTables( $text ) {
                $lines = StringUtils::explode( "\n", $text );
                $out = '';
                $td_history = []; # Is currently a td tag open?
                $last_tag_history = []; # Save history of last lag activated (td, th or caption)
        Severity: Minor
        Found in includes/parser/Parser.php - About 1 day 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 doQuotes has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
        Open

            public function doQuotes( $text ) {
                $arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
                $countarr = count( $arr );
                if ( $countarr == 1 ) {
                    return $text;
        Severity: Minor
        Found in includes/parser/Parser.php - About 1 day 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 makeImage has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
        Open

            public function makeImage( LinkTarget $link, $options, $holders = false ) {
                # Check if the options text is of the form "options|alt text"
                # Options are:
                #  * thumbnail  make a thumbnail with enlarge-icon and caption, alignment depends on lang
                #  * left       no resizing, just left align. label is used for alt= only
        Severity: Minor
        Found in includes/parser/Parser.php - About 1 day 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 handleInternalLinks2 has 272 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function handleInternalLinks2( &$s ) {
                static $tc = false, $e1, $e1_img;
                # the % is needed to support urlencoded titles as well
                if ( !$tc ) {
                    $tc = Title::legalChars() . '#%';
        Severity: Major
        Found in includes/parser/Parser.php - About 1 day to fix

          Function finalizeHeadings has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
          Open

              private function finalizeHeadings( $text, $origText, $isMain = true ) {
                  # Inhibit editsection links if requested in the page
                  if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
                      $maybeShowEditLink = false;
                  } else {
          Severity: Minor
          Found in includes/parser/Parser.php - About 1 day 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 renderImageGallery has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
          Open

              public function renderImageGallery( $text, array $params ) {
                  $mode = false;
                  if ( isset( $params['mode'] ) ) {
                      $mode = $params['mode'];
                  }
          Severity: Minor
          Found in includes/parser/Parser.php - About 1 day 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 finalizeHeadings has 207 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function finalizeHeadings( $text, $origText, $isMain = true ) {
                  # Inhibit editsection links if requested in the page
                  if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
                      $maybeShowEditLink = false;
                  } else {
          Severity: Major
          Found in includes/parser/Parser.php - About 1 day to fix

            Function statelessFetchTemplate has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function statelessFetchTemplate( $page, $parser = false ) {
                    $title = Title::castFromLinkTarget( $page ); // for compatibility with return type
                    $text = $skip = false;
                    $finalTitle = $title;
                    $deps = [];
            Severity: Minor
            Found in includes/parser/Parser.php - About 7 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 makeImage has 167 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function makeImage( LinkTarget $link, $options, $holders = false ) {
                    # Check if the options text is of the form "options|alt text"
                    # Options are:
                    #  * thumbnail  make a thumbnail with enlarge-icon and caption, alignment depends on lang
                    #  * left       no resizing, just left align. label is used for alt= only
            Severity: Major
            Found in includes/parser/Parser.php - About 6 hrs to fix

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

                  private function extractSections( $text, $sectionId, $mode, $newText, ?PageReference $page = null ) {
                      $magicScopeVariable = $this->lock();
                      $this->startParse(
                          $page,
                          ParserOptions::newFromUser( RequestContext::getMain()->getUser() ),
              Severity: Minor
              Found in includes/parser/Parser.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

              Method handleTables has 161 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function handleTables( $text ) {
                      $lines = StringUtils::explode( "\n", $text );
                      $out = '';
                      $td_history = []; # Is currently a td tag open?
                      $last_tag_history = []; # Save history of last lag activated (td, th or caption)
              Severity: Major
              Found in includes/parser/Parser.php - About 6 hrs to fix

                Method doQuotes has 142 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function doQuotes( $text ) {
                        $arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
                        $countarr = count( $arr );
                        if ( $countarr == 1 ) {
                            return $text;
                Severity: Major
                Found in includes/parser/Parser.php - About 5 hrs to fix

                  Method renderImageGallery has 141 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function renderImageGallery( $text, array $params ) {
                          $mode = false;
                          if ( isset( $params['mode'] ) ) {
                              $mode = $params['mode'];
                          }
                  Severity: Major
                  Found in includes/parser/Parser.php - About 5 hrs to fix

                    Function cleanUpTocLine has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function cleanUpTocLine( Node $container ) {
                            '@phan-var Element|DocumentFragment $container';  // @var Element|DocumentFragment $container
                            # Strip out HTML
                            # Allowed tags are:
                            # * <sup> and <sub> (T10393)
                    Severity: Minor
                    Found in includes/parser/Parser.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 statelessFetchTemplate has 120 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public static function statelessFetchTemplate( $page, $parser = false ) {
                            $title = Title::castFromLinkTarget( $page ); // for compatibility with return type
                            $text = $skip = false;
                            $finalTitle = $title;
                            $deps = [];
                    Severity: Major
                    Found in includes/parser/Parser.php - About 4 hrs to fix

                      Function extensionSubstitution has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function extensionSubstitution( array $params, PPFrame $frame, bool $processNowiki = false ) {
                              static $errorStr = '<span class="error">';
                      
                              $name = $frame->expand( $params['name'] );
                              if ( str_starts_with( $name, $errorStr ) ) {
                      Severity: Minor
                      Found in includes/parser/Parser.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 callParserFunction has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function callParserFunction( PPFrame $frame, $function, array $args = [] ) {
                              # Case sensitive functions
                              if ( isset( $this->mFunctionSynonyms[1][$function] ) ) {
                                  $function = $this->mFunctionSynonyms[1][$function];
                              } else {
                      Severity: Minor
                      Found in includes/parser/Parser.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 maybeMakeExternalImage has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private function maybeMakeExternalImage( $url ) {
                              $imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
                              $imagesexception = (bool)$imagesfrom;
                              $text = false;
                              # $imagesfrom could be either a single string or an array of strings, parse out the latter
                      Severity: Minor
                      Found in includes/parser/Parser.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 extractSections has 96 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function extractSections( $text, $sectionId, $mode, $newText, ?PageReference $page = null ) {
                              $magicScopeVariable = $this->lock();
                              $this->startParse(
                                  $page,
                                  ParserOptions::newFromUser( RequestContext::getMain()->getUser() ),
                      Severity: Major
                      Found in includes/parser/Parser.php - About 3 hrs to fix

                        Method callParserFunction has 69 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function callParserFunction( PPFrame $frame, $function, array $args = [] ) {
                                # Case sensitive functions
                                if ( isset( $this->mFunctionSynonyms[1][$function] ) ) {
                                    $function = $this->mFunctionSynonyms[1][$function];
                                } else {
                        Severity: Major
                        Found in includes/parser/Parser.php - About 2 hrs to fix

                          Method magicLinkCallback has 67 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              private function magicLinkCallback( array $m ) {
                                  if ( isset( $m[1] ) && $m[1] !== '' ) {
                                      # Skip anchor
                                      return $m[0];
                                  } elseif ( isset( $m[2] ) && $m[2] !== '' ) {
                          Severity: Major
                          Found in includes/parser/Parser.php - About 2 hrs to fix

                            Method __construct has 21 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                    ServiceOptions $svcOptions,
                                    MagicWordFactory $magicWordFactory,
                                    Language $contLang,
                                    ParserFactory $factory,
                                    UrlUtils $urlUtils,
                            Severity: Major
                            Found in includes/parser/Parser.php - About 2 hrs to fix

                              Method parse has 64 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public function parse(
                                      $text, PageReference $page, ParserOptions $options,
                                      $linestart = true, $clearState = true, $revid = null
                                  ) {
                                      if ( $clearState ) {
                              Severity: Major
                              Found in includes/parser/Parser.php - About 2 hrs to fix

                                Method extensionSubstitution has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public function extensionSubstitution( array $params, PPFrame $frame, bool $processNowiki = false ) {
                                        static $errorStr = '<span class="error">';
                                
                                        $name = $frame->expand( $params['name'] );
                                        if ( str_starts_with( $name, $errorStr ) ) {
                                Severity: Major
                                Found in includes/parser/Parser.php - About 2 hrs to fix

                                  Method makeFreeExternalLink has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      private function makeFreeExternalLink( $url, $numPostProto ) {
                                          $trail = '';
                                  
                                          # The characters '<' and '>' (which were escaped by
                                          # internalRemoveHtmlTags()) should not be included in
                                  Severity: Major
                                  Found in includes/parser/Parser.php - About 2 hrs to fix

                                    Function getImageParams has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private function getImageParams( $handler ) {
                                            if ( $handler ) {
                                                $handlerClass = get_class( $handler );
                                            } else {
                                                $handlerClass = '';
                                    Severity: Minor
                                    Found in includes/parser/Parser.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 extractTagsAndParams has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public static function extractTagsAndParams( array $elements, $text, &$matches ) {
                                            static $n = 1;
                                            $stripped = '';
                                            $matches = [];
                                    
                                    
                                    Severity: Minor
                                    Found in includes/parser/Parser.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 magicLinkCallback has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private function magicLinkCallback( array $m ) {
                                            if ( isset( $m[1] ) && $m[1] !== '' ) {
                                                # Skip anchor
                                                return $m[0];
                                            } elseif ( isset( $m[2] ) && $m[2] !== '' ) {
                                    Severity: Minor
                                    Found in includes/parser/Parser.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 normalizeLinkUrl has 55 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        public static function normalizeLinkUrl( $url ) {
                                            # Test for RFC 3986 IPv6 syntax
                                            $scheme = '[a-z][a-z0-9+.-]*:';
                                            $userinfo = '(?:[a-z0-9\-._~!$&\'()*+,;=:]|%[0-9a-f]{2})*';
                                            $ipv6Host = '\\[((?:[0-9a-f:]|%3[0-A]|%[46][1-6])+)\\]';
                                    Severity: Major
                                    Found in includes/parser/Parser.php - About 2 hrs to fix

                                      Method cleanUpTocLine has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          private function cleanUpTocLine( Node $container ) {
                                              '@phan-var Element|DocumentFragment $container';  // @var Element|DocumentFragment $container
                                              # Strip out HTML
                                              # Allowed tags are:
                                              # * <sup> and <sub> (T10393)
                                      Severity: Major
                                      Found in includes/parser/Parser.php - About 2 hrs to fix

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

                                            private function handleExternalLinks( $text ) {
                                                $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
                                                // @phan-suppress-next-line PhanTypeComparisonFromArray See phan issue #3161
                                                if ( $bits === false ) {
                                                    throw new RuntimeException( "PCRE failure" );
                                        Severity: Major
                                        Found in includes/parser/Parser.php - About 2 hrs to fix

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

                                              protected function makeLimitReport() {
                                                  $maxIncludeSize = $this->mOptions->getMaxIncludeSize();
                                          
                                                  $cpuTime = $this->mOutput->getTimeProfile( 'cpu' );
                                                  if ( $cpuTime !== null ) {
                                          Severity: Minor
                                          Found in includes/parser/Parser.php - About 2 hrs to fix

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

                                                public static function extractTagsAndParams( array $elements, $text, &$matches ) {
                                                    static $n = 1;
                                                    $stripped = '';
                                                    $matches = [];
                                            
                                            
                                            Severity: Minor
                                            Found in includes/parser/Parser.php - About 2 hrs to fix

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

                                                  public function getUserSig( UserIdentity $user, $nickname = false, $fancySig = null ) {
                                                      $username = $user->getName();
                                              
                                                      # If not given, retrieve from the user object.
                                                      if ( $nickname === false ) {
                                              Severity: Minor
                                              Found in includes/parser/Parser.php - About 2 hrs to fix

                                                Method __construct has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                                                Open

                                                    public function __construct(
                                                        ServiceOptions $svcOptions,
                                                        MagicWordFactory $magicWordFactory,
                                                        Language $contLang,
                                                        ParserFactory $factory,
                                                Severity: Minor
                                                Found in includes/parser/Parser.php - About 1 hr to fix

                                                  Method interwikiTransclude has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                                                  Open

                                                      public function interwikiTransclude( LinkTarget $link, $action ) {
                                                          if ( !$this->svcOptions->get( MainConfigNames::EnableScaryTranscluding ) ) {
                                                              return wfMessage( 'scarytranscludedisabled' )->inContentLanguage()->text();
                                                          }
                                                  
                                                  
                                                  Severity: Minor
                                                  Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                        public function getUserSig( UserIdentity $user, $nickname = false, $fancySig = null ) {
                                                            $username = $user->getName();
                                                    
                                                            # If not given, retrieve from the user object.
                                                            if ( $nickname === false ) {
                                                    Severity: Minor
                                                    Found in includes/parser/Parser.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 internalParse has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                                                    Open

                                                        public function internalParse( $text, $isMain = true, $frame = false ) {
                                                            $origText = $text;
                                                    
                                                            # Hook to suspend the parser in this state
                                                            if ( !$this->hookRunner->onParserBeforeInternalParse( $this, $text, $this->mStripState ) ) {
                                                    Severity: Minor
                                                    Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                          private function stripAltText( $caption, $holders ) {
                                                              # Strip bad stuff out of the title (tooltip).  We can't just use
                                                              # replaceLinkHoldersText() here, because if this function is called
                                                              # from handleInternalLinks2(), mLinkHolders won't be up-to-date.
                                                              if ( $holders ) {
                                                      Severity: Minor
                                                      Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                            private function maybeMakeExternalImage( $url ) {
                                                                $imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
                                                                $imagesexception = (bool)$imagesfrom;
                                                                $text = false;
                                                                # $imagesfrom could be either a single string or an array of strings, parse out the latter
                                                        Severity: Minor
                                                        Found in includes/parser/Parser.php - About 1 hr to fix

                                                          Method pstPass2 has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                                                          Open

                                                              private function pstPass2( $text, UserIdentity $user ) {
                                                                  # Note: This is the timestamp saved as hardcoded wikitext to the database, we use
                                                                  # $this->contLang here in order to give everyone the same signature and use the default one
                                                                  # rather than the one selected in each user's preferences.  (see also T14815)
                                                                  $ts = $this->mOptions->getTimestamp();
                                                          Severity: Minor
                                                          Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                                private function handleDoubleUnderscore( $text ) {
                                                                    # The position of __TOC__ needs to be recorded
                                                                    $mw = $this->magicWordFactory->get( 'toc' );
                                                                    if ( $mw->match( $text ) ) {
                                                                        $this->mShowToc = true;
                                                            Severity: Minor
                                                            Found in includes/parser/Parser.php - About 1 hr to fix

                                                              Method getImageParams has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                                                              Open

                                                                  private function getImageParams( $handler ) {
                                                                      if ( $handler ) {
                                                                          $handlerClass = get_class( $handler );
                                                                      } else {
                                                                          $handlerClass = '';
                                                              Severity: Minor
                                                              Found in includes/parser/Parser.php - About 1 hr to fix

                                                                Method getFlatSectionInfo has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                                                                Open

                                                                    public function getFlatSectionInfo( $text ) {
                                                                        $magicScopeVariable = $this->lock();
                                                                        $this->startParse(
                                                                            null,
                                                                            ParserOptions::newFromUser( RequestContext::getMain()->getUser() ),
                                                                Severity: Minor
                                                                Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                                      public function clearState() {
                                                                          $this->resetOutput();
                                                                          $this->mAutonumber = 0;
                                                                          $this->mLinkHolders = new LinkHolderArray(
                                                                              $this,
                                                                  Severity: Minor
                                                                  Found in includes/parser/Parser.php - About 1 hr to fix

                                                                    Method internalParseHalfParsed has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                                                    Open

                                                                        private function internalParseHalfParsed( $text, $isMain = true, $linestart = true ) {
                                                                            $text = $this->mStripState->unstripGeneral( $text );
                                                                    
                                                                            $text = BlockLevelPass::doBlockLevels( $text, $linestart );
                                                                    
                                                                    
                                                                    Severity: Minor
                                                                    Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                                          public function argSubstitution( array $piece, PPFrame $frame ) {
                                                                              $error = false;
                                                                              $parts = $piece['parts'];
                                                                              $nameWithSpaces = $frame->expand( $piece['title'] );
                                                                              $argName = trim( $nameWithSpaces );
                                                                      Severity: Minor
                                                                      Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                                            private function handleExternalLinks( $text ) {
                                                                                $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
                                                                                // @phan-suppress-next-line PhanTypeComparisonFromArray See phan issue #3161
                                                                                if ( $bits === false ) {
                                                                                    throw new RuntimeException( "PCRE failure" );
                                                                        Severity: Minor
                                                                        Found in includes/parser/Parser.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 markerSkipCallback has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                                                        Open

                                                                            public function markerSkipCallback( $s, callable $callback ) {
                                                                                $i = 0;
                                                                                $out = '';
                                                                                while ( $i < strlen( $s ) ) {
                                                                                    $markerStart = strpos( $s, self::MARKER_PREFIX, $i );
                                                                        Severity: Minor
                                                                        Found in includes/parser/Parser.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 cleanSig has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                                                        Open

                                                                            public function cleanSig( $text, $parsing = false ) {
                                                                                if ( !$parsing ) {
                                                                                    $magicScopeVariable = $this->lock();
                                                                                    $this->startParse(
                                                                                        $this->mTitle,
                                                                        Severity: Minor
                                                                        Found in includes/parser/Parser.php - About 1 hr to fix

                                                                          Method handleMagicLinks has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                                                          Open

                                                                              private function handleMagicLinks( $text ) {
                                                                                  $prots = $this->urlUtils->validAbsoluteProtocols();
                                                                                  $urlChar = self::EXT_LINK_URL_CLASS;
                                                                                  $addr = self::EXT_LINK_ADDR;
                                                                                  $space = self::SPACE_NOT_NL; #  non-newline space
                                                                          Severity: Minor
                                                                          Found in includes/parser/Parser.php - About 1 hr to fix

                                                                            Consider simplifying this complex logical expression.
                                                                            Open

                                                                                    if ( isset( $m[1] ) && $m[1] !== '' ) {
                                                                                        # Skip anchor
                                                                                        return $m[0];
                                                                                    } elseif ( isset( $m[2] ) && $m[2] !== '' ) {
                                                                                        # Skip HTML element
                                                                            Severity: Major
                                                                            Found in includes/parser/Parser.php - About 1 hr to fix

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

                                                                                  public function argSubstitution( array $piece, PPFrame $frame ) {
                                                                                      $error = false;
                                                                                      $parts = $piece['parts'];
                                                                                      $nameWithSpaces = $frame->expand( $piece['title'] );
                                                                                      $argName = trim( $nameWithSpaces );
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.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 localizeTOC has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                                              Open

                                                                                  private static function localizeTOC(
                                                                                      ?TOCData $tocData, Language $lang, ?ILanguageConverter $converter
                                                                                  ) {
                                                                                      if ( $tocData === null ) {
                                                                                          return; // Nothing to do
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.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 parseLinkParameter has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                                              Open

                                                                                  private function parseLinkParameter( $value ) {
                                                                                      $chars = self::EXT_LINK_URL_CLASS;
                                                                                      $addr = self::EXT_LINK_ADDR;
                                                                                      $prots = $this->urlUtils->validProtocols();
                                                                                      $type = null;
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.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 makeFreeExternalLink has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                                              Open

                                                                                  private function makeFreeExternalLink( $url, $numPostProto ) {
                                                                                      $trail = '';
                                                                              
                                                                                      # The characters '<' and '>' (which were escaped by
                                                                                      # internalRemoveHtmlTags()) should not be included in
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.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 parse has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                                              Open

                                                                                  public function parse(
                                                                                      $text, PageReference $page, ParserOptions $options,
                                                                                      $linestart = true, $clearState = true, $revid = null
                                                                                  ) {
                                                                                      if ( $clearState ) {
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.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 fetchTemplateAndTitle has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                                                              Open

                                                                                  public function fetchTemplateAndTitle( LinkTarget $link ) {
                                                                                      // Use Title for compatibility with callbacks and return type
                                                                                      $title = Title::newFromLinkTarget( $link );
                                                                              
                                                                                      // Defaults to Parser::statelessFetchTemplate()
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.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 handleDoubleUnderscore has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                                                              Open

                                                                                  private function handleDoubleUnderscore( $text ) {
                                                                                      # The position of __TOC__ needs to be recorded
                                                                                      $mw = $this->magicWordFactory->get( 'toc' );
                                                                                      if ( $mw->match( $text ) ) {
                                                                                          $this->mShowToc = true;
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.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 parse has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                                                              Open

                                                                                      $text, PageReference $page, ParserOptions $options,
                                                                                      $linestart = true, $clearState = true, $revid = null
                                                                              Severity: Minor
                                                                              Found in includes/parser/Parser.php - About 45 mins to fix

                                                                                Avoid deeply nested control flow statements.
                                                                                Open

                                                                                                        if ( $firstspace == -1 ) {
                                                                                                            $firstspace = $i;
                                                                                                        }
                                                                                Severity: Major
                                                                                Found in includes/parser/Parser.php - About 45 mins to fix

                                                                                  Consider simplifying this complex logical expression.
                                                                                  Open

                                                                                          if ( $text === false && $parts->getLength() > 0
                                                                                              && ( $this->ot['html']
                                                                                                  || $this->ot['pre']
                                                                                                  || ( $this->ot['wiki'] && $frame->isTemplate() )
                                                                                              )
                                                                                  Severity: Major
                                                                                  Found in includes/parser/Parser.php - About 40 mins to fix

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

                                                                                        public function startExternalParse( ?PageReference $page, ParserOptions $options,
                                                                                            $outputType, $clearState = true, $revId = null
                                                                                    Severity: Minor
                                                                                    Found in includes/parser/Parser.php - About 35 mins to fix

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

                                                                                              $text,
                                                                                              ?PageReference $page,
                                                                                              ParserOptions $options,
                                                                                              $revid = null,
                                                                                              $frame = false
                                                                                      Severity: Minor
                                                                                      Found in includes/parser/Parser.php - About 35 mins to fix

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

                                                                                                $text,
                                                                                                PageReference $page,
                                                                                                UserIdentity $user,
                                                                                                ParserOptions $options,
                                                                                                $clearState = true
                                                                                        Severity: Minor
                                                                                        Found in includes/parser/Parser.php - About 35 mins to fix

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

                                                                                              private function extractSections( $text, $sectionId, $mode, $newText, ?PageReference $page = null ) {
                                                                                          Severity: Minor
                                                                                          Found in includes/parser/Parser.php - About 35 mins to fix

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

                                                                                                public function getExternalLinkAttribs( $url ) {
                                                                                                    $attribs = [];
                                                                                                    $rel = self::getExternalLinkRel( $url, $this->getTitle() ) ?? '';
                                                                                            
                                                                                                    $target = $this->mOptions->getExternalLinkTarget();
                                                                                            Severity: Minor
                                                                                            Found in includes/parser/Parser.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 getRevisionUser has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                                            Open

                                                                                                public function getRevisionUser(): ?string {
                                                                                                    if ( $this->mRevisionUser === null ) {
                                                                                                        $revObject = $this->getRevisionRecordObject();
                                                                                            
                                                                                                        # if this template is subst: the revision id will be blank,
                                                                                            Severity: Minor
                                                                                            Found in includes/parser/Parser.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 normalizeLinkUrl has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                                            Open

                                                                                                public static function normalizeLinkUrl( $url ) {
                                                                                                    # Test for RFC 3986 IPv6 syntax
                                                                                                    $scheme = '[a-z][a-z0-9+.-]*:';
                                                                                                    $userinfo = '(?:[a-z0-9\-._~!$&\'()*+,;=:]|%[0-9a-f]{2})*';
                                                                                                    $ipv6Host = '\\[((?:[0-9a-f:]|%3[0-A]|%[46][1-6])+)\\]';
                                                                                            Severity: Minor
                                                                                            Found in includes/parser/Parser.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 setFunctionHook has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                                            Open

                                                                                                public function setFunctionHook( $id, callable $callback, $flags = 0 ) {
                                                                                                    $oldVal = $this->mFunctionHooks[$id][0] ?? null;
                                                                                                    $this->mFunctionHooks[$id] = [ $callback, $flags ];
                                                                                            
                                                                                                    # Add to function cache
                                                                                            Severity: Minor
                                                                                            Found in includes/parser/Parser.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 $m[0];
                                                                                            Severity: Major
                                                                                            Found in includes/parser/Parser.php - About 30 mins to fix

                                                                                              Avoid too many return statements within this method.
                                                                                              Open

                                                                                                          return $m[0];
                                                                                              Severity: Major
                                                                                              Found in includes/parser/Parser.php - About 30 mins to fix

                                                                                                Avoid too many return statements within this method.
                                                                                                Open

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

                                                                                                  Avoid too many return statements within this method.
                                                                                                  Open

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

                                                                                                    Avoid too many return statements within this method.
                                                                                                    Open

                                                                                                                return Linker::makeExternalLink(
                                                                                                                    $url,
                                                                                                                    "{$keyword} {$id}",
                                                                                                                    true,
                                                                                                                    $cssClass,
                                                                                                    Severity: Major
                                                                                                    Found in includes/parser/Parser.php - About 30 mins to fix

                                                                                                      Avoid too many return statements within this method.
                                                                                                      Open

                                                                                                                  return $this->getLinkRenderer()->makeKnownLink(
                                                                                                                      SpecialPage::getTitleFor( 'Booksources', $num ),
                                                                                                                      "ISBN $isbn",
                                                                                                                      [
                                                                                                                          'class' => 'internal mw-magiclink-isbn',
                                                                                                      Severity: Major
                                                                                                      Found in includes/parser/Parser.php - About 30 mins to fix

                                                                                                        Avoid too many return statements within this method.
                                                                                                        Open

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

                                                                                                          Avoid too many return statements within this method.
                                                                                                          Open

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

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

                                                                                                                public function internalParse( $text, $isMain = true, $frame = false ) {
                                                                                                                    $origText = $text;
                                                                                                            
                                                                                                                    # Hook to suspend the parser in this state
                                                                                                                    if ( !$this->hookRunner->onParserBeforeInternalParse( $this, $text, $this->mStripState ) ) {
                                                                                                            Severity: Minor
                                                                                                            Found in includes/parser/Parser.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

                                                                                                                            } elseif ( $thislen == 3 ) {
                                                                                                                                // three quotes - open or close bold
                                                                                                                                if ( $state === 'b' ) {
                                                                                                                                    $output .= '</b>';
                                                                                                                                    $state = '';
                                                                                                            Severity: Major
                                                                                                            Found in includes/parser/Parser.php and 1 other location - About 1 hr to fix
                                                                                                            includes/parser/Parser.php on lines 2067..2124

                                                                                                            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 115.

                                                                                                            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

                                                                                                                            if ( $thislen == 2 ) {
                                                                                                                                // two quotes - open or close italics
                                                                                                                                if ( $state === 'i' ) {
                                                                                                                                    $output .= '</i>';
                                                                                                                                    $state = '';
                                                                                                            Severity: Major
                                                                                                            Found in includes/parser/Parser.php and 1 other location - About 1 hr to fix
                                                                                                            includes/parser/Parser.php on lines 2085..2103

                                                                                                            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 115.

                                                                                                            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