howardjones/network-weathermap

View on GitHub
lib/Weathermap/Plugins/Datasources/SNMP3.php

Summary

Maintainability
B
6 hrs
Test Coverage

Method copyParamsFromCacti has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function copyParamsFromCacti($profileName, $hostId)
    {
        $params = array();

        foreach ($this->snmpParamDefaults as $keyname => $default) {
Severity: Minor
Found in lib/Weathermap/Plugins/Datasources/SNMP3.php - About 1 hr to fix

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

        private function getSNMPData($host, $params, $oids, &$item, $timeout, $retries)
        {
            $channels = array(
                'in' => IN,
                'out' => OUT
    Severity: Minor
    Found in lib/Weathermap/Plugins/Datasources/SNMP3.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 getSNMPData has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function getSNMPData($host, $params, $oids, &$item, $timeout, $retries)
        {
            $channels = array(
                'in' => IN,
                'out' => OUT
    Severity: Minor
    Found in lib/Weathermap/Plugins/Datasources/SNMP3.php - About 1 hr to fix

      Method getSNMPData has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          private function getSNMPData($host, $params, $oids, &$item, $timeout, $retries)
      Severity: Minor
      Found in lib/Weathermap/Plugins/Datasources/SNMP3.php - About 45 mins to fix

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

            private function copyParamsFromCacti($profileName, $hostId)
            {
                $params = array();
        
                foreach ($this->snmpParamDefaults as $keyname => $default) {
        Severity: Minor
        Found in lib/Weathermap/Plugins/Datasources/SNMP3.php - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Define a constant instead of duplicating this literal "username" 4 times.
        Open

                "username" => "",

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Define a constant instead of duplicating this literal "authpass" 3 times.
        Open

                "authpass" => "",

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Define a constant instead of duplicating this literal "privproto" 5 times.
        Open

                "privproto" => ""

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Define a constant instead of duplicating this literal "seclevel" 4 times.
        Open

                "seclevel" => "noAuthNoPriv",

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Define a constant instead of duplicating this literal "authproto" 3 times.
        Open

                "authproto" => "",

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Define a constant instead of duplicating this literal "privpass" 4 times.
        Open

                "privpass" => "",

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        There are no issues that match your filters.

        Category
        Status