librenms/librenms

View on GitHub
LibreNMS/OS/Ciscowlc.php

Summary

Maintainability
C
7 hrs
Test Coverage

Method pollOS has 74 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function pollOS(DataStorageInterface $datastore): void
    {
        $device = $this->getDeviceArray();
        $apNames = \SnmpQuery::enumStrings()->walk('AIRESPACE-WIRELESS-MIB::bsnAPName')->table(1);
        $radios = \SnmpQuery::enumStrings()->walk('AIRESPACE-WIRELESS-MIB::bsnAPIfTable')->table(2);
Severity: Major
Found in LibreNMS/OS/Ciscowlc.php - About 2 hrs to fix

    Function pollOS has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        public function pollOS(DataStorageInterface $datastore): void
        {
            $device = $this->getDeviceArray();
            $apNames = \SnmpQuery::enumStrings()->walk('AIRESPACE-WIRELESS-MIB::bsnAPName')->table(1);
            $radios = \SnmpQuery::enumStrings()->walk('AIRESPACE-WIRELESS-MIB::bsnAPIfTable')->table(2);
    Severity: Minor
    Found in LibreNMS/OS/Ciscowlc.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 discoverWirelessClients has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function discoverWirelessClients()
        {
            $counts = $this->getCacheByIndex('bsnDot11EssNumberOfMobileStations', 'AIRESPACE-WIRELESS-MIB');
            if (empty($counts)) {
                return []; // no counts to be had
    Severity: Minor
    Found in LibreNMS/OS/Ciscowlc.php - About 1 hr to fix

      Avoid assigning values to variables in if clauses and the like (line '125', column '21').
      Open

          public function pollOS(DataStorageInterface $datastore): void
          {
              $device = $this->getDeviceArray();
              $apNames = \SnmpQuery::enumStrings()->walk('AIRESPACE-WIRELESS-MIB::bsnAPName')->table(1);
              $radios = \SnmpQuery::enumStrings()->walk('AIRESPACE-WIRELESS-MIB::bsnAPIfTable')->table(2);
      Severity: Minor
      Found in LibreNMS/OS/Ciscowlc.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

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

                      $rrd_def = RrdDefinition::make()
                          ->addDataset('channel', 'GAUGE', 0, 200)
                          ->addDataset('txpow', 'GAUGE', 0, 200)
                          ->addDataset('radioutil', 'GAUGE', 0, 100)
                          ->addDataset('nummonclients', 'GAUGE', 0, 500)
      Severity: Major
      Found in LibreNMS/OS/Ciscowlc.php and 8 other locations - About 1 hr to fix
      LibreNMS/OS/Vrp.php on lines 233..240
      includes/polling/applications/asterisk.inc.php on lines 28..35
      includes/polling/applications/freeradius.inc.php on lines 73..80
      includes/polling/applications/freeradius.inc.php on lines 149..156
      includes/polling/applications/freeradius.inc.php on lines 178..185
      includes/polling/applications/freeswitch.inc.php on lines 23..30
      includes/polling/applications/mailscanner.inc.php on lines 15..22
      includes/polling/aruba-controller.inc.php on lines 97..104

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

      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

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

                      $ap = new AccessPoint([
      Severity: Minor
      Found in LibreNMS/OS/Ciscowlc.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