librenms/librenms

View on GitHub
scripts/removespikes.php

Summary

Maintainability
F
1 wk
Test Coverage

Function updateXML has a Cognitive Complexity of 80 (exceeds 5 allowed). Consider refactoring.
Open

function updateXML(&$output, &$rra)
{
    global $numspike, $percent, $avgnan, $method, $total_kills;
    $new_array = [];

Severity: Minor
Found in scripts/removespikes.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 removespikes.php has 696 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/php -q
<?php
/*
 ex: set tabstop=4 shiftwidth=4 autoindent:
 +-------------------------------------------------------------------------+
Severity: Major
Found in scripts/removespikes.php - About 1 day to fix

    Function calculateOverallStatistics has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
    Open

    function calculateOverallStatistics(&$rra, &$samples)
    {
        global $percent, $stddev, $ds_min, $ds_max, $var_kills, $std_kills;
    
        $rra_num = 0;
    Severity: Minor
    Found in scripts/removespikes.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 outputStatistics has 128 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function outputStatistics($rra)
    {
        global $rra_cf, $rra_name, $ds_name, $rra_pdp, $html;
    
        if (sizeof($rra)) {
    Severity: Major
    Found in scripts/removespikes.php - About 5 hrs to fix

      Function outputStatistics has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

      function outputStatistics($rra)
      {
          global $rra_cf, $rra_name, $ds_name, $rra_pdp, $html;
      
          if (sizeof($rra)) {
      Severity: Minor
      Found in scripts/removespikes.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 removeComments has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

      function removeComments(&$output)
      {
          $new_array = [];
          if (sizeof($output)) {
              foreach ($output as $line) {
      Severity: Minor
      Found in scripts/removespikes.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 calculateOverallStatistics has 70 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function calculateOverallStatistics(&$rra, &$samples)
      {
          global $percent, $stddev, $ds_min, $ds_max, $var_kills, $std_kills;
      
          $rra_num = 0;
      Severity: Major
      Found in scripts/removespikes.php - About 2 hrs to fix

        Method updateXML has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function updateXML(&$output, &$rra)
        {
            global $numspike, $percent, $avgnan, $method, $total_kills;
            $new_array = [];
        
        
        Severity: Major
        Found in scripts/removespikes.php - About 2 hrs to fix

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

          function calculateVarianceAverages(&$rra, &$samples)
          {
              global $outliers;
          
              if (sizeof($samples)) {
          Severity: Minor
          Found in scripts/removespikes.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 displayTime has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          function displayTime($pdp)
          {
              global $step;
          
              $total_time = $pdp * $step; // seconds
          Severity: Minor
          Found in scripts/removespikes.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 backupRRDFile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          function backupRRDFile($rrdfile)
          {
              global $using_cacti, $tempdir, $seed, $html;
          
              if ($using_cacti) {
          Severity: Minor
          Found in scripts/removespikes.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 function outputStatistics() has 133 lines of code. Current threshold is set to 100. Avoid really long methods.
          Open

          function outputStatistics($rra)
          {
              global $rra_cf, $rra_name, $ds_name, $rra_pdp, $html;
          
              if (sizeof($rra)) {
          Severity: Minor
          Found in scripts/removespikes.php by phpmd

          The function outputStatistics() has an NPath complexity of 16777223. The configured NPath complexity threshold is 200.
          Open

          function outputStatistics($rra)
          {
              global $rra_cf, $rra_name, $ds_name, $rra_pdp, $html;
          
              if (sizeof($rra)) {
          Severity: Minor
          Found in scripts/removespikes.php by phpmd

          NPathComplexity

          Since: 0.1

          The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

          Example

          class Foo {
              function bar() {
                  // lots of complicated code
              }
          }

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

          The function outputStatistics() has a Cyclomatic Complexity of 55. The configured cyclomatic complexity threshold is 10.
          Open

          function outputStatistics($rra)
          {
              global $rra_cf, $rra_name, $ds_name, $rra_pdp, $html;
          
              if (sizeof($rra)) {
          Severity: Minor
          Found in scripts/removespikes.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

          The function updateXML() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
          Open

          function updateXML(&$output, &$rra)
          {
              global $numspike, $percent, $avgnan, $method, $total_kills;
              $new_array = [];
          
          
          Severity: Minor
          Found in scripts/removespikes.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

          The function calculateOverallStatistics() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
          Open

          function calculateOverallStatistics(&$rra, &$samples)
          {
              global $percent, $stddev, $ds_min, $ds_max, $var_kills, $std_kills;
          
              $rra_num = 0;
          Severity: Minor
          Found in scripts/removespikes.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

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

              } else {
                  $total_time = $total_time / 60;
          
                  if ($total_time < 60) {
                      return $total_time . ' mins';
          Severity: Minor
          Found in scripts/removespikes.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 createRRDFileFromXML uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

              } else {
                  $response = shell_exec("rrdtool restore -f -r $xmlfile $rrdfile");
              }
          Severity: Minor
          Found in scripts/removespikes.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 removeComments uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                              } else {
                                  $line = trim(substr($line, 0, $comment_start - 1) . substr($line, $comment_end + 3));
                              }
          Severity: Minor
          Found in scripts/removespikes.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 calculateOverallStatistics uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                                          } else {
                                              $rra[$rra_num][$ds_num]['numnksamples']++;
                                              $rra[$rra_num][$ds_num]['sumnksamples'] += $sample;
                                          }
          Severity: Minor
          Found in scripts/removespikes.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 removeComments uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                          } else {
                              $comment_end = strpos($line, '-->');
                              if ($comment_start == 0) {
                                  $line = trim(substr($line, $comment_end + 3));
                              } else {
          Severity: Minor
          Found in scripts/removespikes.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 displayTime uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      $total_time = $total_time / 60;
          
                      if ($total_time < 24) {
                          return $total_time . ' hours';
          Severity: Minor
          Found in scripts/removespikes.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 updateXML uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                                              } else {
                                                  $dsvalue = 'NaN';
                                              }
          Severity: Minor
          Found in scripts/removespikes.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 calculateOverallStatistics uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                              } else {
                                  $rra[$rra_num][$ds_num]['standard_deviation'] = 'N/A';
                                  $rra[$rra_num][$ds_num]['average'] = 'N/A';
                                  $rra[$rra_num][$ds_num]['min_cutoff'] = 'N/A';
                                  $rra[$rra_num][$ds_num]['max_cutoff'] = 'N/A';
          Severity: Minor
          Found in scripts/removespikes.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 backupRRDFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

              } else {
                  $backupdir = $tempdir;
              }
          Severity: Minor
          Found in scripts/removespikes.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 calculateVarianceAverages uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                              } else {
                                  rsort($ds, SORT_NUMERIC);
                                  $ds = array_slice($ds, $outliers);
          
                                  sort($ds, SORT_NUMERIC);
          Severity: Minor
          Found in scripts/removespikes.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 updateXML uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                              } else {
                                  if ($method == 2) {
                                      if ($dsvalue > (1 + $percent) * $rra[$rra_num][$ds_num]['variance_avg']) {
                                          if ($kills < $numspike) {
                                              if ($avgnan == 'avg') {
          Severity: Minor
          Found in scripts/removespikes.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 displayTime uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                      } else {
                          $total_time = $total_time / 24;
          
                          return $total_time . ' days';
                      }
          Severity: Minor
          Found in scripts/removespikes.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 outputStatistics uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                  } else {
                      printf(
                          "<tr><th style='width:10%%;'>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
                          'Size',
                          'DataSource',
          Severity: Minor
          Found in scripts/removespikes.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 updateXML uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                                              } else {
                                                  $dsvalue = 'NaN';
                                              }
          Severity: Minor
          Found in scripts/removespikes.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 updateXML uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                      } else {
                          if (substr_count($line, '</rra>')) {
                              $ds_minmax = [];
                              $rra_num++;
                              $kills = 0;
          Severity: Minor
          Found in scripts/removespikes.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 removeComments uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                      } else {
                          /* is there a comment, remove it */
                          $comment_start = strpos($line, '<!--');
                          if ($comment_start === false) {
                              /* do nothing no line */
          Severity: Minor
          Found in scripts/removespikes.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 display_help uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

              } else {
                  $version = 'v1.0';
              }
          Severity: Minor
          Found in scripts/removespikes.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 updateXML uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

                                  } else {
                                      if (($dsvalue > $rra[$rra_num][$ds_num]['max_cutoff']) ||
                                      ($dsvalue < $rra[$rra_num][$ds_num]['min_cutoff'])) {
                                          if ($kills < $numspike) {
                                              if ($avgnan == 'avg') {
          Severity: Minor
          Found in scripts/removespikes.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 backupRRDFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

              } else {
                  $newfile = basename($rrdfile);
              }
          Severity: Minor
          Found in scripts/removespikes.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 unused local variables such as '$rra_name'.
          Open

              global $rra_cf, $rra_name, $ds_name, $rra_pdp, $html;
          Severity: Minor
          Found in scripts/removespikes.php by phpmd

          UnusedLocalVariable

          Since: 0.2

          Detects when a local variable is declared and/or assigned, but not used.

          Example

          class Foo {
              public function doSomething()
              {
                  $i = 5; // Unused
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

          Avoid unused local variables such as '$ds'.
          Open

                          foreach ($dses as $ds) {
          Severity: Minor
          Found in scripts/removespikes.php by phpmd

          UnusedLocalVariable

          Since: 0.2

          Detects when a local variable is declared and/or assigned, but not used.

          Example

          class Foo {
              public function doSomething()
              {
                  $i = 5; // Unused
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

          Avoid unused local variables such as '$ds_minmax'.
          Open

                              $ds_minmax = [];
          Severity: Minor
          Found in scripts/removespikes.php by phpmd

          UnusedLocalVariable

          Since: 0.2

          Detects when a local variable is declared and/or assigned, but not used.

          Example

          class Foo {
              public function doSomething()
              {
                  $i = 5; // Unused
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

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

                      foreach ($rra as $rra_key => $dses) {
                          if (sizeof($dses)) {
                              foreach ($dses as $dskey => $ds) {
                                  printf(
                                      '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>' .
          Severity: Major
          Found in scripts/removespikes.php and 1 other location - About 3 days to fix
          scripts/removespikes.php on lines 622..654

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

          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

                      foreach ($rra as $rra_key => $dses) {
                          if (sizeof($dses)) {
                              foreach ($dses as $dskey => $ds) {
                                  printf(
                                      '%10s %16s %10s %7s %7s ' .
          Severity: Major
          Found in scripts/removespikes.php and 1 other location - About 3 days to fix
          scripts/removespikes.php on lines 676..708

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

          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

          A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 420 and the first side effect is on line 29.
          Open

          #!/usr/bin/php -q
          Severity: Minor
          Found in scripts/removespikes.php by phpcodesniffer

          There are no issues that match your filters.

          Category
          Status