librenms/librenms

View on GitHub
LibreNMS/Util/ModuleTestHelper.php

Summary

Maintainability
F
4 days
Test Coverage

File ModuleTestHelper.php has 550 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * ModuleTester.php
 *
 * -Description-
Severity: Major
Found in LibreNMS/Util/ModuleTestHelper.php - About 1 day to fix

    Function convertSnmpToSnmprec has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        private function convertSnmpToSnmprec(SnmpResponse $snmp_data): array
        {
            $result = [];
            foreach (explode(PHP_EOL, $snmp_data->raw) as $line) {
                if (empty($line)) {
    Severity: Minor
    Found in LibreNMS/Util/ModuleTestHelper.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

    Method generateTestData has 99 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function generateTestData(Snmpsim $snmpsim, $no_save = false)
        {
            global $device;
            Config::set('rrd.enable', false); // disable rrd
            Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
    Severity: Major
    Found in LibreNMS/Util/ModuleTestHelper.php - About 3 hrs to fix

      The class ModuleTestHelper has an overall complexity of 108 which is very high. The configured complexity threshold is 50.
      Open

      class ModuleTestHelper
      {
          private $quiet = false;
          private $modules;
          private $variant;
      Severity: Minor
      Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

      Function generateTestData has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function generateTestData(Snmpsim $snmpsim, $no_save = false)
          {
              global $device;
              Config::set('rrd.enable', false); // disable rrd
              Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
      Severity: Minor
      Found in LibreNMS/Util/ModuleTestHelper.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

      ModuleTestHelper has 25 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class ModuleTestHelper
      {
          private $quiet = false;
          private $modules;
          private $variant;
      Severity: Minor
      Found in LibreNMS/Util/ModuleTestHelper.php - About 2 hrs to fix

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

            public static function findOsWithData($modules = [], string $os_filter = null)
            {
                $os_list = [];
        
                foreach (glob(Config::get('install_dir') . '/tests/data/*.json') as $file) {
        Severity: Minor
        Found in LibreNMS/Util/ModuleTestHelper.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 collectOids has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function collectOids($device_id)
            {
                global $device;
        
                $device = device_by_id_cache($device_id);
        Severity: Minor
        Found in LibreNMS/Util/ModuleTestHelper.php - About 1 hr to fix

          Function captureFromDevice has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
              {
                  if ($full) {
                      $snmp_oids[][] = [
                          'oid' => '.',
          Severity: Minor
          Found in LibreNMS/Util/ModuleTestHelper.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 convertSnmpToSnmprec has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function convertSnmpToSnmprec(SnmpResponse $snmp_data): array
              {
                  $result = [];
                  foreach (explode(PHP_EOL, $snmp_data->raw) as $line) {
                      if (empty($line)) {
          Severity: Minor
          Found in LibreNMS/Util/ModuleTestHelper.php - About 1 hr to fix

            Method findOsWithData has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function findOsWithData($modules = [], string $os_filter = null)
                {
                    $os_list = [];
            
                    foreach (glob(Config::get('install_dir') . '/tests/data/*.json') as $file) {
            Severity: Minor
            Found in LibreNMS/Util/ModuleTestHelper.php - About 1 hr to fix

              Method saveSnmprec has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
                  {
                      $filename = $this->snmprec_file;
              
                      if ($context) {
              Severity: Minor
              Found in LibreNMS/Util/ModuleTestHelper.php - About 1 hr to fix

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

                    public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
                    {
                        if ($full) {
                            $snmp_oids[][] = [
                                'oid' => '.',
                Severity: Minor
                Found in LibreNMS/Util/ModuleTestHelper.php - About 1 hr to fix

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

                      private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
                      {
                          $filename = $this->snmprec_file;
                  
                          if ($context) {
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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

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

                      private function cleanSnmprecData(&$data)
                      {
                          $private_oid = [
                              '1.3.6.1.2.1.1.6.0',
                              '1.3.6.1.2.1.1.4.0',
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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

                  The method generateTestData() has an NPath complexity of 3072. The configured NPath complexity threshold is 200.
                  Open

                      public function generateTestData(Snmpsim $snmpsim, $no_save = false)
                      {
                          global $device;
                          Config::set('rrd.enable', false); // disable rrd
                          Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 method generateTestData() has 142 lines of code. Current threshold is set to 100. Avoid really long methods.
                  Open

                      public function generateTestData(Snmpsim $snmpsim, $no_save = false)
                      {
                          global $device;
                          Config::set('rrd.enable', false); // disable rrd
                          Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

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

                      public function generateTestData(Snmpsim $snmpsim, $no_save = false)
                      {
                          global $device;
                          Config::set('rrd.enable', false); // disable rrd
                          Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 convertSnmpToSnmprec() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
                  Open

                      private function convertSnmpToSnmprec(SnmpResponse $snmp_data): array
                      {
                          $result = [];
                          foreach (explode(PHP_EOL, $snmp_data->raw) as $line) {
                              if (empty($line)) {
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 class ModuleTestHelper has a coupling between objects value of 20. Consider to reduce the number of dependencies under 13.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CouplingBetweenObjects

                  Since: 1.1.0

                  A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                  Example

                  class Foo {
                      /**
                       * @var \foo\bar\X
                       */
                      private $x = null;
                  
                      /**
                       * @var \foo\bar\Y
                       */
                      private $y = null;
                  
                      /**
                       * @var \foo\bar\Z
                       */
                      private $z = null;
                  
                      public function setFoo(\Foo $foo) {}
                      public function setBar(\Bar $bar) {}
                      public function setBaz(\Baz $baz) {}
                  
                      /**
                       * @return \SplObjectStorage
                       * @throws \OutOfRangeException
                       * @throws \InvalidArgumentException
                       * @throws \ErrorException
                       */
                      public function process(\Iterator $it) {}
                  
                      // ...
                  }

                  Source https://phpmd.org/rules/design.html#couplingbetweenobjects

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

                      public function setQuiet($quiet = true)
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 getJsonFilepath has a boolean flag argument $short, which is a certain sign of a Single Responsibility Principle violation.
                  Open

                      public function getJsonFilepath($short = false)
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 saveSnmprec has a boolean flag argument $prefer_new, which is a certain sign of a Single Responsibility Principle violation.
                  Open

                      private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 captureFromDevice has a boolean flag argument $prefer_new, which is a certain sign of a Single Responsibility Principle violation.
                  Open

                      public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 saveSnmprec has a boolean flag argument $write, which is a certain sign of a Single Responsibility Principle violation.
                  Open

                      private function saveSnmprec(array $data, ?string $context = null, bool $write = true, bool $prefer_new = false): string
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 generateTestData has a boolean flag argument $no_save, which is a certain sign of a Single Responsibility Principle violation.
                  Open

                      public function generateTestData(Snmpsim $snmpsim, $no_save = false)
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 captureFromDevice has a boolean flag argument $full, which is a certain sign of a Single Responsibility Principle violation.
                  Open

                      public function captureFromDevice(int $device_id, bool $prefer_new = false, bool $full = false): void
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 qPrint uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              echo $var;
                          }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 convertSnmpToSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                                  } else {
                                      $result[key($result)] = "$oid|4x|" . bin2hex($data . PHP_EOL . $line);
                                  }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 convertSnmpToSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  // multi-line data, append to last
                                  $last = end($result);
                  
                                  [$oid, $type, $data] = explode('|', $last, 3);
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 saveSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              $results = array_merge($new_data, $existing_data);
                          }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 '563', column '14').
                  Open

                      public function generateTestData(Snmpsim $snmpsim, $no_save = false)
                      {
                          global $device;
                          Config::set('rrd.enable', false); // disable rrd
                          Config::set('rrdtool_version', '1.7.2'); // don't detect rrdtool version, rrdtool is not install on ci
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 getDiscoveryOutput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  return "Module $module not run. Modules: " . implode(',', array_keys($this->poller_module_output));
                              }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 saveSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              $existing_data = [];
                          }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 findOsWithData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $valid_modules = array_intersect($modules, $data_modules);
                              }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 getPollerOutput uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  return "Module $module not run. Modules: " . implode(',', array_keys($this->poller_module_output));
                              }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 saveSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                              } else {
                                  $this->qPrint("\nSaved snmprec data $filename\n");
                                  file_put_contents($filename, $output);
                              }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 convertSnmpToSnmprec uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                                  } else {
                                      [$raw_type, $data] = explode(':', $raw_data, 2);
                                      if (Str::startsWith($raw_type, 'Wrong Type (should be ')) {
                                          // device returned the wrong type, save the wrong type to emulate the device behavior
                                          [$raw_type, $data] = explode(':', ltrim($data), 2);
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 generateTestData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                                  } else {
                                      $existing_data[$module] = $module_data;
                                  }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 captureFromDevice uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              $snmp_oids = $this->collectOids($device_id);
                          }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 extractVariant uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              [$rvar, $ros] = explode('_', strrev($full_name), 2);
                  
                              return [strrev($ros), strrev($rvar)];
                          }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 generateTestData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              ob_flush();
                          }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 generateTestData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                  Open

                          } else {
                              ob_flush();
                          }
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 '$app'.
                  Open

                          app()->bind(\LibreNMS\Util\AutonomousSystem::class, function ($app, $parameters) {
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 private methods such as 'compareOid'.
                  Open

                      private static function compareOid($a, $b)
                      {
                          $a_oid = explode('.', $a);
                          $b_oid = explode('.', $b);
                  
                  
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  UnusedPrivateMethod

                  Since: 0.2

                  Unused Private Method detects when a private method is declared but is unused.

                  Example

                  class Something
                  {
                      private function foo() {} // unused
                  }

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

                  The method findOsWithData() contains an exit expression.
                  Open

                                  exit(1);
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  ExitExpression

                  Since: 0.2

                  An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

                  Example

                  class Foo {
                      public function bar($param)  {
                          if ($param === 42) {
                              exit(23);
                          }
                      }
                  }

                  Source https://phpmd.org/rules/design.html#exitexpression

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

                      private $discovery_module_output = [];
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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

                  The property $exclude_from_all is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

                  The property $discovery_module_output is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

                  The property $discovery_output is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

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

                              [$os, $variant] = self::extractVariant($file);
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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

                  The property $snmprec_file is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

                  The property $json_file is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

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

                      private static function compareOid($a, $b)
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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

                  The property $snmprec_dir is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

                  The property $json_dir is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

                  The property $poller_output is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

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

                      public function __construct($modules, $os, $variant = '')
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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 $b. Configured minimum length is 3.
                  Open

                      private static function compareOid($a, $b)
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.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

                  The property $file_name is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

                  The property $poller_module_output is not named in camelCase.
                  Open

                  class ModuleTestHelper
                  {
                      private $quiet = false;
                      private $modules;
                      private $variant;
                  Severity: Minor
                  Found in LibreNMS/Util/ModuleTestHelper.php by phpmd

                  CamelCasePropertyName

                  Since: 0.2

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

                  Example

                  class ClassName {
                      protected $property_name;
                  }

                  Source

                  There are no issues that match your filters.

                  Category
                  Status