librenms/librenms

View on GitHub
includes/common.php

Summary

Maintainability
F
3 days
Test Coverage

File common.php has 559 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
 * LibreNMS - Common Functions
 *
 * Original Observium version by: Adam Armstrong, Tom Laermans
Severity: Major
Found in includes/common.php - About 1 day to fix

    Function ResolveGlues has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

    function ResolveGlues($tables, $target, $x = 0, $hist = [], $last = [])
    {
        if (sizeof($tables) == 1 && $x != 0) {
            if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', [$tables[0], $target]) == 1) {
                return array_merge($last, [$tables[0] . '.' . $target]);
    Severity: Minor
    Found in includes/common.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 ResolveGlues has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function ResolveGlues($tables, $target, $x = 0, $hist = [], $last = [])
    {
        if (sizeof($tables) == 1 && $x != 0) {
            if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', [$tables[0], $target]) == 1) {
                return array_merge($last, [$tables[0] . '.' . $target]);
    Severity: Major
    Found in includes/common.php - About 2 hrs to fix

      Method external_exec has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function external_exec($command)
      {
          $device = DeviceCache::getPrimary();
      
          $proc = new Process($command);
      Severity: Major
      Found in includes/common.php - About 2 hrs to fix

        Method c_echo has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function c_echo($string, $enabled = true)
        {
            if (! $enabled) {
                return;
            }
        Severity: Minor
        Found in includes/common.php - About 1 hr to fix

          Function external_exec has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          function external_exec($command)
          {
              $device = DeviceCache::getPrimary();
          
              $proc = new Process($command);
          Severity: Minor
          Found in includes/common.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 ResolveGlues has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          function ResolveGlues($tables, $target, $x = 0, $hist = [], $last = [])
          Severity: Minor
          Found in includes/common.php - About 35 mins to fix

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

            function get_graph_subtypes($type, $device = null)
            {
                $type = basename($type);
                $types = [];
            
            
            Severity: Minor
            Found in includes/common.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 $value;
            Severity: Major
            Found in includes/common.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                                      return array_merge($last, [$table . '.' . $target]);
              Severity: Major
              Found in includes/common.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                                return $tmp;
                Severity: Major
                Found in includes/common.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return array_merge($last, [
                                      'locations.id',
                                      'devices.device_id.location_id',
                                  ]);
                  Severity: Major
                  Found in includes/common.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return array_merge($last, [
                                        'application_metrics.app_id',
                                        "applications.$target",
                                    ]);
                    Severity: Major
                    Found in includes/common.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                          return $tmp;
                      Severity: Major
                      Found in includes/common.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                            return false;
                        Severity: Major
                        Found in includes/common.php - About 30 mins to fix

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

                          function is_client_authorized($clientip)
                          {
                              if (Config::get('allow_unauth_graphs', false)) {
                                  d_echo("Unauthorized graphs allowed\n");
                          
                          
                          Severity: Minor
                          Found in includes/common.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

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

                          function c_echo($string, $enabled = true)
                          {
                              if (! $enabled) {
                                  return;
                              }
                          Severity: Minor
                          Found in includes/common.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 external_exec() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                          Open

                          function external_exec($command)
                          {
                              $device = DeviceCache::getPrimary();
                          
                              $proc = new Process($command);
                          Severity: Minor
                          Found in includes/common.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 ResolveGlues() has a Cyclomatic Complexity of 22. The configured cyclomatic complexity threshold is 10.
                          Open

                          function ResolveGlues($tables, $target, $x = 0, $hist = [], $last = [])
                          {
                              if (sizeof($tables) == 1 && $x != 0) {
                                  if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', [$tables[0], $target]) == 1) {
                                      return array_merge($last, [$tables[0] . '.' . $target]);
                          Severity: Minor
                          Found in includes/common.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 device_by_id_cache has a boolean flag argument $refresh, which is a certain sign of a Single Responsibility Principle violation.
                          Open

                          function device_by_id_cache($device_id, $refresh = false)
                          Severity: Minor
                          Found in includes/common.php by phpmd

                          BooleanArgumentFlag

                          Since: 1.4.0

                          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

                          Example

                          class Foo {
                              public function bar($flag = true) {
                              }
                          }

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

                          The method get_ports_mapped has a boolean flag argument $with_statistics, which is a certain sign of a Single Responsibility Principle violation.
                          Open

                          function get_ports_mapped($device_id, $with_statistics = false)
                          Severity: Minor
                          Found in includes/common.php by phpmd

                          BooleanArgumentFlag

                          Since: 1.4.0

                          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

                          Example

                          class Foo {
                              public function bar($flag = true) {
                              }
                          }

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

                          Missing class import via use statement (line '416', column '22').
                          Open

                              $smokeping = new \LibreNMS\Util\Smokeping(DeviceCache::get((int) $device['device_id']));
                          Severity: Minor
                          Found in includes/common.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 c_echo has a boolean flag argument $enabled, which is a certain sign of a Single Responsibility Principle violation.
                          Open

                          function c_echo($string, $enabled = true)
                          Severity: Minor
                          Found in includes/common.php by phpmd

                          BooleanArgumentFlag

                          Since: 1.4.0

                          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

                          Example

                          class Foo {
                              public function bar($flag = true) {
                              }
                          }

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

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

                              } else {
                                  $port = get_port_by_ifIndex($device_id, $ifIndex);
                                  $port_index_cache[$device_id][$ifIndex] = $port;
                              }
                          Severity: Minor
                          Found in includes/common.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 get_ports_mapped uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                              } else {
                                  /* Query all information available for ports for this device ... */
                                  $query = 'SELECT * FROM `ports` WHERE `device_id` = ? ORDER BY port_id';
                              }
                          Severity: Minor
                          Found in includes/common.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 truncate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

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

                              } else {
                                  return $string;
                              }
                          Severity: Minor
                          Found in includes/common.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 get_sensor_rrd_name uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                              } else {
                                  return ['sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']];
                              }
                          Severity: Minor
                          Found in includes/common.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 get_port_by_id uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                                  } else {
                                      return false;
                                  }
                          Severity: Minor
                          Found in includes/common.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 assigning values to variables in if clauses and the like (line '400', column '9').
                          Open

                          function get_graph_subtypes($type, $device = null)
                          {
                              $type = basename($type);
                              $types = [];
                          
                          
                          Severity: Minor
                          Found in includes/common.php by phpmd

                          IfStatementAssignment

                          Since: 2.7.0

                          Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

                          Example

                          class Foo
                          {
                              public function bar($flag)
                              {
                                  if ($foo = 'bar') { // possible typo
                                      // ...
                                  }
                                  if ($baz = 0) { // always false
                                      // ...
                                  }
                              }
                          }

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

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

                                  } else {
                                      return false;
                                  }
                          Severity: Minor
                          Found in includes/common.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 ResolveGlues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                                              } else {
                                                  [$tmp] = explode('_', $glue['COLUMN_NAME']);
                                                  $tmp .= 's';
                                                  if (! in_array($tmp, $tables) && ! in_array($tmp, $hist)) {
                                                      //Expand table
                          Severity: Minor
                          Found in includes/common.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 ResolveGlues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                                      } else {
                                          foreach ($glues as $glue) {
                                              if ($glue['COLUMN_NAME'] == $target) {
                                                  return array_merge($last, [$table . '.' . $target]);
                                              } else {
                          Severity: Minor
                          Found in includes/common.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 get_entity_by_id_cache uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                              } else {
                                  $entity = dbFetchRow('SELECT * FROM `' . $table . '` WHERE `' . $type . '_id` = ?', [$id]);
                                  $entity_cache[$type][$id] = $entity;
                              }
                          Severity: Minor
                          Found in includes/common.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 c_echo uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                              } else {
                                  echo preg_replace('/%((%)|.)/', '', $string);
                              }
                          Severity: Minor
                          Found in includes/common.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 print_error uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                              } else {
                                  echo '<div class="alert alert-danger"><i class="fa fa-fw fa-exclamation-circle" aria-hidden="true"></i> ' . $text . '</div>';
                              }
                          Severity: Minor
                          Found in includes/common.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 print_message uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                              } else {
                                  echo '<div class="alert alert-success"><i class="fa fa-fw fa-check-circle" aria-hidden="true"></i> ' . $text . '</div>';
                              }
                          Severity: Minor
                          Found in includes/common.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 get_device_id_by_port_id uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                                  } else {
                                      return false;
                                  }
                          Severity: Minor
                          Found in includes/common.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 round_Nth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                                  } else {
                                      $ret = $val - $diff;
                                  }
                          Severity: Minor
                          Found in includes/common.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 ResolveGlues uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                              } else {
                                  $x++;
                                  if ($x > 30) {
                                      //Too much recursion. Abort.
                                      return false;
                          Severity: Minor
                          Found in includes/common.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 c_echo uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                          Open

                                  } else {
                                      // limited functionality for validate.php
                                      $search = [
                                          '/%n/',
                                          '/%g/',
                          Severity: Minor
                          Found in includes/common.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 parameters such as '$refresh'.
                          Open

                          function accesspoint_by_id($ap_id, $refresh = '0')
                          Severity: Minor
                          Found in includes/common.php by phpmd

                          UnusedFormalParameter

                          Since: 0.2

                          Avoid passing parameters to methods or constructors and then not using those parameters.

                          Example

                          class Foo
                          {
                              private function bar($howdy)
                              {
                                  // $howdy is not used
                              }
                          }

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

                          Avoid unused parameters such as '$device'.
                          Open

                          function get_graph_subtypes($type, $device = null)
                          Severity: Minor
                          Found in includes/common.php by phpmd

                          UnusedFormalParameter

                          Since: 0.2

                          Avoid passing parameters to methods or constructors and then not using those parameters.

                          Example

                          class Foo
                          {
                              private function bar($howdy)
                              {
                                  // $howdy is not used
                              }
                          }

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

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

                          function get_port_id($ports_mapped, $port, $port_association_mode)
                          Severity: Minor
                          Found in includes/common.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 variables with short names like $id. Configured minimum length is 3.
                          Open

                          function get_entity_by_id_cache($type, $id)
                          Severity: Minor
                          Found in includes/common.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 $i. Configured minimum length is 3.
                          Open

                              $i = 1;
                          Severity: Minor
                          Found in includes/common.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 $ap. Configured minimum length is 3.
                          Open

                              $ap = dbFetchRow('SELECT * FROM `access_points` WHERE `accesspoint_id` = ?', [$ap_id]);
                          Severity: Minor
                          Found in includes/common.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 $l. Configured minimum length is 3.
                          Open

                              $l = strlen($ip);
                          Severity: Minor
                          Found in includes/common.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 $id. Configured minimum length is 3.
                          Open

                          function getifbyid($id)
                          Severity: Minor
                          Found in includes/common.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 $x. Configured minimum length is 3.
                          Open

                          function ResolveGlues($tables, $target, $x = 0, $hist = [], $last = [])
                          Severity: Minor
                          Found in includes/common.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 $ip. Configured minimum length is 3.
                          Open

                          function inet6_ntop($ip)
                          Severity: Minor
                          Found in includes/common.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

                          There are no issues that match your filters.

                          Category
                          Status