librenms/librenms

View on GitHub
LibreNMS/OS/Routeros.php

Summary

Maintainability
F
4 days
Test Coverage

File Routeros.php has 362 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Routeros.php
 *
 * Mikrotik RouterOS
Severity: Minor
Found in LibreNMS/OS/Routeros.php - About 4 hrs to fix

    The class Routeros has 12 public methods. Consider refactoring Routeros to keep number of public methods under 10.
    Open

    class Routeros extends OS implements
        OSPolling,
        WirelessCcqDiscovery,
        WirelessClientsDiscovery,
        WirelessFrequencyDiscovery,
    Severity: Minor
    Found in LibreNMS/OS/Routeros.php by phpmd

    TooManyPublicMethods

    Since: 0.1

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

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

    Example

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

    Method discoverWirelessRate has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function discoverWirelessRate()
        {
            $sensors = [];
    
            $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
    Severity: Major
    Found in LibreNMS/OS/Routeros.php - About 2 hrs to fix

      Method discoverWirelessFrequency has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function discoverWirelessFrequency()
          {
              $sensors = [];
              $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
              foreach ($data as $index => $entry) {
      Severity: Minor
      Found in LibreNMS/OS/Routeros.php - About 1 hr to fix

        Method discoverWirelessCcq has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function discoverWirelessCcq()
            {
                $sensors = [];
        
                $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
        Severity: Minor
        Found in LibreNMS/OS/Routeros.php - About 1 hr to fix

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

              public function discoverWirelessCcq()
              {
                  $sensors = [];
          
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
          Severity: Minor
          Found in LibreNMS/OS/Routeros.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 discoverWirelessRate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function discoverWirelessRate()
              {
                  $sensors = [];
          
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
          Severity: Minor
          Found in LibreNMS/OS/Routeros.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 discoverWirelessFrequency has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function discoverWirelessFrequency()
              {
                  $sensors = [];
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
                  foreach ($data as $index => $entry) {
          Severity: Minor
          Found in LibreNMS/OS/Routeros.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 discoverWirelessRate() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
          Open

              public function discoverWirelessRate()
              {
                  $sensors = [];
          
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
          Severity: Minor
          Found in LibreNMS/OS/Routeros.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

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

                  foreach ($data as $index => $entry) {
                      if ($entry['mtxrWlStatTxRate'] === '0' && $entry['mtxrWlStatRxRate'] === '0') {
                          continue;  // no data
                      }
                      $freq = $entry['mtxrWlStatFreq'] ? substr($entry['mtxrWlStatFreq'], 0, 1) . 'G' : 'SSID';
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 1 other location - About 5 hrs to fix
          LibreNMS/OS/Routeros.php on lines 292..316

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 193.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

                  foreach ($data as $index => $entry) {
                      if ($entry['mtxrWlApTxRate'] === '0' && $entry['mtxrWlApRxRate'] === '0') {
                          continue;  // no data
                      }
          
          
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 1 other location - About 5 hrs to fix
          LibreNMS/OS/Routeros.php on lines 319..342

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 193.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

              public function discoverWirelessClients()
              {
                  $sensors = [];
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
                  foreach ($data as $index => $entry) {
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 1 other location - About 2 hrs to fix
          LibreNMS/OS/Routeros.php on lines 259..279

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 130.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

              public function discoverWirelessNoiseFloor()
              {
                  $sensors = [];
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
          
          
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 1 other location - About 2 hrs to fix
          LibreNMS/OS/Routeros.php on lines 122..141

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 130.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

                  foreach ($data as $index => $entry) {
                      if ($entry['mtxrWlApFreq'] === '0') {
                          continue;
                      }
                      $freq = substr($entry['mtxrWlApFreq'], 0, 1) . 'G';
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 1 other location - About 1 hr to fix
          LibreNMS/OS/Routeros.php on lines 170..184

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 106.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

                  foreach ($data as $index => $entry) {
                      if ($entry['mtxrWlStatFreq'] === '0') {
                          continue;
                      }
                      $freq = substr($entry['mtxrWlStatFreq'], 0, 1) . 'G';
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 1 other location - About 1 hr to fix
          LibreNMS/OS/Routeros.php on lines 153..167

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 106.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

              public function discoverWirelessRsrq()
              {
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrLTEModemTable');
          
                  $sensors = [];
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 2 other locations - About 1 hr to fix
          LibreNMS/OS/Routeros.php on lines 422..441
          LibreNMS/OS/Routeros.php on lines 449..468

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 102.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

              public function discoverWirelessSinr()
              {
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrLTEModemTable');
          
                  $sensors = [];
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 2 other locations - About 1 hr to fix
          LibreNMS/OS/Routeros.php on lines 395..414
          LibreNMS/OS/Routeros.php on lines 422..441

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 102.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

              public function discoverWirelessRsrp()
              {
                  $data = $this->getCacheTable('MIKROTIK-MIB::mtxrLTEModemTable');
          
                  $sensors = [];
          Severity: Major
          Found in LibreNMS/OS/Routeros.php and 2 other locations - About 1 hr to fix
          LibreNMS/OS/Routeros.php on lines 395..414
          LibreNMS/OS/Routeros.php on lines 449..468

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 102.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status