XoopsModules25x/apcal

View on GitHub
include/Text_Diff_Renderer.php

Summary

Maintainability
C
7 hrs
Test Coverage

Function render has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    public function render($diff)
    {
        $xi      = $yi = 1;
        $block   = false;
        $context = array();
Severity: Minor
Found in include/Text_Diff_Renderer.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

The class Text_Diff_Renderer has 13 public methods. Consider refactoring Text_Diff_Renderer to keep number of public methods under 10.
Open

class Text_Diff_Renderer
{
    /**
     * Number of leading context "lines" to preserve.
     *
Severity: Minor
Found in include/Text_Diff_Renderer.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Method render has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function render($diff)
    {
        $xi      = $yi = 1;
        $block   = false;
        $context = array();
Severity: Minor
Found in include/Text_Diff_Renderer.php - About 1 hr to fix

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

        public function _block($xbeg, $xlen, $ybeg, $ylen, &$edits)
    Severity: Minor
    Found in include/Text_Diff_Renderer.php - About 35 mins to fix

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

          public function _block($xbeg, $xlen, $ybeg, $ylen, &$edits)
          {
              $output = $this->_startBlock($this->_blockHeader($xbeg, $xlen, $ybeg, $ylen));
      
              foreach ($edits as $edit) {
      Severity: Minor
      Found in include/Text_Diff_Renderer.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

      The method render() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
      Open

          public function render($diff)
          {
              $xi      = $yi = 1;
              $block   = false;
              $context = array();
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

      Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

      Missing class import via use statement (line '102', column '40').
      Open

                              $block[] = new Text_Diff_Op_copy($context);
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

      Source http://phpmd.org/rules/cleancode.html#MissingImport

      Missing class import via use statement (line '88', column '44').
      Open

                                  $block[] = new Text_Diff_Op_copy($context);
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      MissingImport

      Since: 2.7.0

      Importing all external classes in a file through use statements makes them clearly visible.

      Example

      function make() {
          return new \stdClass();
      }

      Source http://phpmd.org/rules/cleancode.html#MissingImport

      The method render uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      if (!is_array($block)) {
                          $context = array_slice($context, count($context) - $nlead);
                          $x0      = $xi - count($context);
                          $y0      = $yi - count($context);
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      The method render uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                          } else {
                              if ($ntrail) {
                                  $context = array_slice($edit->orig, 0, $ntrail);
                                  $block[] = new Text_Diff_Op_copy($context);
                              }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid excessively long variable names like $_trailing_context_lines. Keep variable name length under 20.
      Open

          public $_trailing_context_lines = 0;
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#longvariable

      Avoid excessively long variable names like $_leading_context_lines. Keep variable name length under 20.
      Open

          public $_leading_context_lines = 0;
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#longvariable

      Each class must be in a namespace of at least one level (a top-level vendor name)
      Open

      class Text_Diff_Renderer

      The property $_trailing_context_lines is not named in camelCase.
      Open

      class Text_Diff_Renderer
      {
          /**
           * Number of leading context "lines" to preserve.
           *
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The class Text_Diff_Renderer is not named in CamelCase.
      Open

      class Text_Diff_Renderer
      {
          /**
           * Number of leading context "lines" to preserve.
           *
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseClassName

      Since: 0.2

      It is considered best practice to use the CamelCase notation to name classes.

      Example

      class class_name {
      }

      Source

      The property $_leading_context_lines is not named in camelCase.
      Open

      class Text_Diff_Renderer
      {
          /**
           * Number of leading context "lines" to preserve.
           *
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      Avoid variables with short names like $yi. Configured minimum length is 3.
      Open

              $xi      = $yi = 1;
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      Avoid variables with short names like $xi. Configured minimum length is 3.
      Open

              $xi      = $yi = 1;
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      Avoid variables with short names like $v. Configured minimum length is 3.
      Open

                  $v = '_' . $param;
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      Method name "_endDiff" should not be prefixed with an underscore to indicate visibility
      Open

          public function _endDiff()

      Property name "$_trailing_context_lines" should not be prefixed with an underscore to indicate visibility
      Open

          public $_trailing_context_lines = 0;

      Method name "_added" should not be prefixed with an underscore to indicate visibility
      Open

          public function _added($lines)

      Method name "_lines" should not be prefixed with an underscore to indicate visibility
      Open

          public function _lines($lines, $prefix = ' ')

      Method name "_startBlock" should not be prefixed with an underscore to indicate visibility
      Open

          public function _startBlock($header)

      Method name "_context" should not be prefixed with an underscore to indicate visibility
      Open

          public function _context($lines)

      Method name "_changed" should not be prefixed with an underscore to indicate visibility
      Open

          public function _changed($orig, $final)

      Property name "$_leading_context_lines" should not be prefixed with an underscore to indicate visibility
      Open

          public $_leading_context_lines = 0;

      Method name "_endBlock" should not be prefixed with an underscore to indicate visibility
      Open

          public function _endBlock()

      Method name "_startDiff" should not be prefixed with an underscore to indicate visibility
      Open

          public function _startDiff()

      Method name "_blockHeader" should not be prefixed with an underscore to indicate visibility
      Open

          public function _blockHeader($xbeg, $xlen, $ybeg, $ylen)

      Method name "_deleted" should not be prefixed with an underscore to indicate visibility
      Open

          public function _deleted($lines)

      Method name "_block" should not be prefixed with an underscore to indicate visibility
      Open

          public function _block($xbeg, $xlen, $ybeg, $ylen, &$edits)

      Class name "Text_Diff_Renderer" is not in camel caps format
      Open

      class Text_Diff_Renderer

      The method _endBlock is not named in camelCase.
      Open

          public function _endBlock()
          {
              return '';
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _lines is not named in camelCase.
      Open

          public function _lines($lines, $prefix = ' ')
          {
              return $prefix . implode("\n$prefix", $lines) . "\n";
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _endDiff is not named in camelCase.
      Open

          public function _endDiff()
          {
              return '';
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _blockHeader is not named in camelCase.
      Open

          public function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
          {
              if ($xlen > 1) {
                  $xbeg .= ',' . ($xbeg + $xlen - 1);
              }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _startBlock is not named in camelCase.
      Open

          public function _startBlock($header)
          {
              return $header . "\n";
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _block is not named in camelCase.
      Open

          public function _block($xbeg, $xlen, $ybeg, $ylen, &$edits)
          {
              $output = $this->_startBlock($this->_blockHeader($xbeg, $xlen, $ybeg, $ylen));
      
              foreach ($edits as $edit) {
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _context is not named in camelCase.
      Open

          public function _context($lines)
          {
              return $this->_lines($lines);
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _changed is not named in camelCase.
      Open

          public function _changed($orig, $final)
          {
              return $this->_deleted($orig) . "---\n" . $this->_added($final);
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _startDiff is not named in camelCase.
      Open

          public function _startDiff()
          {
              return '';
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _deleted is not named in camelCase.
      Open

          public function _deleted($lines)
          {
              return $this->_lines($lines, '<');
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      The method _added is not named in camelCase.
      Open

          public function _added($lines)
          {
              return $this->_lines($lines, '>');
          }
      Severity: Minor
      Found in include/Text_Diff_Renderer.php by phpmd

      CamelCaseMethodName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name methods.

      Example

      class ClassName {
          public function get_name() {
          }
      }

      Source

      There are no issues that match your filters.

      Category
      Status