wikimedia/mediawiki-core

View on GitHub
includes/tidy/RemexCompatMunger.php

Summary

Maintainability
D
2 days
Test Coverage

File RemexCompatMunger.php has 369 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace MediaWiki\Tidy;

use InvalidArgumentException;
Severity: Minor
Found in includes/tidy/RemexCompatMunger.php - About 4 hrs to fix

    Method insertElement has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function insertElement( $preposition, $refElement, Element $element, $void,
            $sourceStart, $sourceLength
        ) {
            [ $parent, $newRef ] = $this->getParentForInsert( $preposition, $refElement );
            $parentData = $parent->snData;
    Severity: Major
    Found in includes/tidy/RemexCompatMunger.php - About 2 hrs to fix

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

          public function insertElement( $preposition, $refElement, Element $element, $void,
              $sourceStart, $sourceLength
          ) {
              [ $parent, $newRef ] = $this->getParentForInsert( $preposition, $refElement );
              $parentData = $parent->snData;
      Severity: Minor
      Found in includes/tidy/RemexCompatMunger.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 splitTagStack has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function splitTagStack( SerializerNode $parentNode, $inline, $pos ) {
              $parentData = $parentNode->snData;
              $wrapBase = $parentData->wrapBaseNode;
              $pWrap = $parentData->ancestorPNode;
              if ( !$pWrap ) {
      Severity: Major
      Found in includes/tidy/RemexCompatMunger.php - About 2 hrs to fix

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

            private function splitTagStack( SerializerNode $parentNode, $inline, $pos ) {
                $parentData = $parentNode->snData;
                $wrapBase = $parentData->wrapBaseNode;
                $pWrap = $parentData->ancestorPNode;
                if ( !$pWrap ) {
        Severity: Minor
        Found in includes/tidy/RemexCompatMunger.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

        Consider simplifying this complex logical expression.
        Open

                if ( isset( self::$metadataElements[$elementName] )
                    && !self::isTableOfContentsMarker( $element )
                ) {
                    // The element is a metadata element, that we allow to appear in
                    // both inline and block contexts.
        Severity: Critical
        Found in includes/tidy/RemexCompatMunger.php - About 1 hr to fix

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

              private function getParentForInsert( $preposition, $refElement ) {
                  if ( $preposition === TreeBuilder::ROOT ) {
                      return [ $this->serializer->getRootNode(), null ];
                  } elseif ( $preposition === TreeBuilder::BEFORE ) {
                      $refNode = $refElement->userData;
          Severity: Minor
          Found in includes/tidy/RemexCompatMunger.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

          Method characters has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function characters( $preposition, $refElement, $text, $start, $length,
                  $sourceStart, $sourceLength
          Severity: Major
          Found in includes/tidy/RemexCompatMunger.php - About 50 mins to fix

            Method doctype has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
            Severity: Minor
            Found in includes/tidy/RemexCompatMunger.php - About 45 mins to fix

              Method insertElement has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public function insertElement( $preposition, $refElement, Element $element, $void,
                      $sourceStart, $sourceLength
              Severity: Minor
              Found in includes/tidy/RemexCompatMunger.php - About 45 mins to fix

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

                    public function comment( $preposition, $refElement, $text, $sourceStart, $sourceLength ) {
                Severity: Minor
                Found in includes/tidy/RemexCompatMunger.php - About 35 mins to fix

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

                      public function characters( $preposition, $refElement, $text, $start, $length,
                          $sourceStart, $sourceLength
                      ) {
                          $isBlank = strspn( $text, "\t\n\f\r ", $start, $length ) === $length;
                  
                  
                  Severity: Minor
                  Found in includes/tidy/RemexCompatMunger.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

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

                      private static $formattingElements = [
                          'a' => true,
                          'b' => true,
                          'big' => true,
                          'code' => true,
                  Severity: Major
                  Found in includes/tidy/RemexCompatMunger.php and 1 other location - About 1 hr to fix
                  includes/Storage/DerivedPageDataUpdater.php on lines 176..195

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

                  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