wikimedia/mediawiki-core

View on GitHub
includes/libs/Diff/DiffEngine.php

Summary

Maintainability
F
1 wk
Test Coverage

Function find_middle_snake has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring.
Open

    private function find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
        $from = &$this->from;
        $to = &$this->to;
        $V0 = &$V[0];
        $V1 = &$V[1];
Severity: Minor
Found in includes/libs/Diff/DiffEngine.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

File DiffEngine.php has 494 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * New version of the difference engine
 *
 * Copyright © 2008 Guy Van den Broeck <guy@guyvdb.eu>
Severity: Minor
Found in includes/libs/Diff/DiffEngine.php - About 7 hrs to fix

    Method find_middle_snake has 174 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
            $from = &$this->from;
            $to = &$this->to;
            $V0 = &$V[0];
            $V1 = &$V[1];
    Severity: Major
    Found in includes/libs/Diff/DiffEngine.php - About 6 hrs to fix

      Function shiftBoundaries has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
      Open

          private function shiftBoundaries( array $lines, array &$changed, array $other_changed ) {
              $i = 0;
              $j = 0;
      
              assert( count( $lines ) == count( $changed ) );
      Severity: Minor
      Found in includes/libs/Diff/DiffEngine.php - About 6 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function diffInternal has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function diffInternal( array $from, array $to ) {
              // remember initial lengths
              $m = count( $from );
              $n = count( $to );
      
      
      Severity: Minor
      Found in includes/libs/Diff/DiffEngine.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 diffInternal has 92 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function diffInternal( array $from, array $to ) {
              // remember initial lengths
              $m = count( $from );
              $n = count( $to );
      
      
      Severity: Major
      Found in includes/libs/Diff/DiffEngine.php - About 3 hrs to fix

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

            private static function findMostProgress( $M, $N, $limit, $V ) {
                $delta = $N - $M;
        
                if ( ( $M & 1 ) == ( $limit & 1 ) ) {
                    $forward_start_diag = max( -$M, -$limit );
        Severity: Minor
        Found in includes/libs/Diff/DiffEngine.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 shiftBoundaries has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function shiftBoundaries( array $lines, array &$changed, array $other_changed ) {
                $i = 0;
                $j = 0;
        
                assert( count( $lines ) == count( $changed ) );
        Severity: Major
        Found in includes/libs/Diff/DiffEngine.php - About 2 hrs to fix

          Method findMostProgress has 58 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private static function findMostProgress( $M, $N, $limit, $V ) {
                  $delta = $N - $M;
          
                  if ( ( $M & 1 ) == ( $limit & 1 ) ) {
                      $forward_start_diag = max( -$M, -$limit );
          Severity: Major
          Found in includes/libs/Diff/DiffEngine.php - About 2 hrs to fix

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

                public function diff( $from_lines, $to_lines ) {
                    // Diff and store locally
                    $this->diffInternal( $from_lines, $to_lines );
            
                    // Merge edits when possible
            Severity: Minor
            Found in includes/libs/Diff/DiffEngine.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 ( $delta & 1 ) {
                        for ( $d = 0; $d <= $limit; ++$d ) {
                            $start_diag = max( $value_to_add_forward + $start_forward, -$d );
                            $end_diag = min( $end_forward, $d );
                            $value_to_add_forward = 1 - $value_to_add_forward;
            Severity: Critical
            Found in includes/libs/Diff/DiffEngine.php - About 1 hr to fix

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

                  public function diff( $from_lines, $to_lines ) {
                      // Diff and store locally
                      $this->diffInternal( $from_lines, $to_lines );
              
                      // Merge edits when possible
              Severity: Minor
              Found in includes/libs/Diff/DiffEngine.php - About 1 hr to fix

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

                    private function find_middle_snake( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
                Severity: Minor
                Found in includes/libs/Diff/DiffEngine.php - About 45 mins to fix

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

                      private function lcs_rec( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
                  Severity: Minor
                  Found in includes/libs/Diff/DiffEngine.php - About 45 mins to fix

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

                        private function lcs_rec( $bottoml1, $topl1, $bottoml2, $topl2, &$V, &$snake ) {
                            // check that both sequences are non-empty
                            if ( $bottoml1 > $topl1 || $bottoml2 > $topl2 ) {
                                return 0;
                            }
                    Severity: Minor
                    Found in includes/libs/Diff/DiffEngine.php - About 35 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    There are no issues that match your filters.

                    Category
                    Status