howardjones/network-weathermap

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

Summary

Maintainability
F
5 days
Test Coverage

Function readFromPollerOutput has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

    private function readFromPollerOutput($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)
    {
        global $config;

        $pdo = weathermap_get_pdo();
Severity: Minor
Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 7 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

Function readFromRealRRDtool has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

    private function readFromRealRRDtool($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)
    {
        MapUtility::debug("RRD ReadData: traditional style\n");

        // we get the last 800 seconds of data - this might be 1 or 2 lines, depending on when in the
Severity: Minor
Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 6 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

File RRDTool.php has 414 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
// RRDtool datasource plugin.
//     gauge:filename.rrd:ds_in:ds_out
//     filename.rrd:ds_in:ds_out
//     filename.rrd:ds_in:ds_out
Severity: Minor
Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 5 hrs to fix

    Function readData has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        public function readData($targetString, &$map, &$mapItem)
        {
            $this->data[IN] = null;
            $this->data[OUT] = null;
            $dsnames = array(IN => "traffic_in", OUT => "traffic_out");
    Severity: Minor
    Found in lib/Weathermap/Plugins/Datasources/RRDTool.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 readData has 96 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function readData($targetString, &$map, &$mapItem)
        {
            $this->data[IN] = null;
            $this->data[OUT] = null;
            $dsnames = array(IN => "traffic_in", OUT => "traffic_out");
    Severity: Major
    Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 3 hrs to fix

      Function readFromRealRRDtoolWithAggregate has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          private function readFromRealRRDtoolWithAggregate(
              $rrdfile,
              $cf,
              $aggregatefn,
              $start,
      Severity: Minor
      Found in lib/Weathermap/Plugins/Datasources/RRDTool.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

      Method readFromRealRRDtool has 86 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function readFromRealRRDtool($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)
          {
              MapUtility::debug("RRD ReadData: traditional style\n");
      
              // we get the last 800 seconds of data - this might be 1 or 2 lines, depending on when in the
      Severity: Major
      Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 3 hrs to fix

        Method readFromRealRRDtoolWithAggregate has 76 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function readFromRealRRDtoolWithAggregate(
                $rrdfile,
                $cf,
                $aggregatefn,
                $start,
        Severity: Major
        Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 3 hrs to fix

          Method readFromPollerOutput has 75 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function readFromPollerOutput($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)
              {
                  global $config;
          
                  $pdo = weathermap_get_pdo();
          Severity: Major
          Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 3 hrs to fix

            Method init has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function init(&$map)
                {
                    global $config;
            
                    if ($map->context == 'cacti') {
            Severity: Minor
            Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 1 hr to fix

              Method readFromRealRRDtoolWithAggregate has 8 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                      $rrdfile,
                      $cf,
                      $aggregatefn,
                      $start,
                      $end,
              Severity: Major
              Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 1 hr to fix

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

                    public function init(&$map)
                    {
                        global $config;
                
                        if ($map->context == 'cacti') {
                Severity: Minor
                Found in lib/Weathermap/Plugins/Datasources/RRDTool.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

                Method readFromRealRRDtool has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    private function readFromRealRRDtool($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)
                Severity: Major
                Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 50 mins to fix

                  Method readFromPollerOutput has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      private function readFromPollerOutput($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)
                  Severity: Major
                  Found in lib/Weathermap/Plugins/Datasources/RRDTool.php - About 50 mins to fix

                    Refactor this function to reduce its Cognitive Complexity from 49 to the 15 allowed.
                    Open

                        private function readFromPollerOutput($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)

                    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

                    See

                    Refactor this function to reduce its Cognitive Complexity from 43 to the 15 allowed.
                    Open

                        private function readFromRealRRDtool($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)

                    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

                    See

                    Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed.
                    Open

                        private function readFromRealRRDtoolWithAggregate(

                    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

                    See

                    Refactor this function to reduce its Cognitive Complexity from 33 to the 15 allowed.
                    Open

                        public function readData($targetString, &$map, &$mapItem)

                    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

                    See

                    This function has 8 parameters, which is greater than the 7 authorized.
                    Open

                        private function readFromRealRRDtoolWithAggregate(
                            $rrdfile,
                            $cf,
                            $aggregatefn,
                            $start,

                    A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

                    Noncompliant Code Example

                    With a maximum number of 4 parameters:

                    function doSomething($param1, $param2, $param3, $param4, $param5) {
                    ...
                    }
                    

                    Compliant Solution

                    function doSomething($param1, $param2, $param3, $param4) {
                    ...
                    }
                    

                    Remove the unused function parameter "$start".
                    Open

                        private function readFromPollerOutput($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)

                    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

                    Noncompliant Code Example

                    function doSomething($a, $b) { // "$a" is unused
                      return compute($b);
                    }
                    

                    Compliant Solution

                    function doSomething($b) {
                      return compute($b);
                    }
                    

                    Exceptions

                    Functions in classes that override a class or implement interfaces are ignored.

                    class C extends B {
                    
                      function doSomething($a, $b) {     // no issue reported on $b
                        compute($a);
                      }
                    
                    }
                    

                    See

                    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
                    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
                    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
                    • CERT, MSC12-CPP. - Detect and remove code that has no effect

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

                                MapUtility::debug("RRD DS: path_rra is " . $config["rra_path"] . " - your rrd pathname must be exactly this to use poller_output\n");

                    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 "local_data_id" 10 times.
                    Open

                                        if (!isset($result['local_data_id'])) {

                    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 " and " 3 times.
                    Open

                                MapUtility::warn("RRD ReadData: At least one of your DS names (" . $dsnames[IN] . " and " . $dsnames[OUT] . ") were not found, even though there was a valid data line. Maybe they are wrong? Valid DS names in this file are: $names [WMRRD06]\n");

                    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.

                    Remove this commented out code.
                    Open

                    //            $map->rrdtool_check = "FOUND";

                    Programmers should not comment out code as it bloats programs and reduces readability.

                    Unused code should be deleted and can be retrieved from source control history if required.

                    See

                    • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
                    • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
                    • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
                    • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

                    Remove this commented out code.
                    Open

                            # $command = $map->rrdtool . " graph /dev/null -f ''  --start $start --end $end ";

                    Programmers should not comment out code as it bloats programs and reduces readability.

                    Unused code should be deleted and can be retrieved from source control history if required.

                    See

                    • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
                    • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
                    • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
                    • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

                    Remove this commented out code.
                    Open

                    //include_once dirname(__FILE__) . "/../Utility.phpace Weathermap\Plugins\Datasources;

                    Programmers should not comment out code as it bloats programs and reduces readability.

                    Unused code should be deleted and can be retrieved from source control history if required.

                    See

                    • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
                    • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
                    • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
                    • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

                    Remove the unused function parameter "$cf".
                    Open

                        private function readFromPollerOutput($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)

                    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

                    Noncompliant Code Example

                    function doSomething($a, $b) { // "$a" is unused
                      return compute($b);
                    }
                    

                    Compliant Solution

                    function doSomething($b) {
                      return compute($b);
                    }
                    

                    Exceptions

                    Functions in classes that override a class or implement interfaces are ignored.

                    class C extends B {
                    
                      function doSomething($a, $b) {     // no issue reported on $b
                        compute($a);
                      }
                    
                    }
                    

                    See

                    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
                    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
                    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
                    • CERT, MSC12-CPP. - Detect and remove code that has no effect

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

                            if ($map->context == 'cacti') {

                    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.

                    Remove the unused function parameter "$item".
                    Open

                        private function readFromRealRRDtool($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)

                    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

                    Noncompliant Code Example

                    function doSomething($a, $b) { // "$a" is unused
                      return compute($b);
                    }
                    

                    Compliant Solution

                    function doSomething($b) {
                      return compute($b);
                    }
                    

                    Exceptions

                    Functions in classes that override a class or implement interfaces are ignored.

                    class C extends B {
                    
                      function doSomething($a, $b) {     // no issue reported on $b
                        compute($a);
                      }
                    
                    }
                    

                    See

                    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
                    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
                    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
                    • CERT, MSC12-CPP. - Detect and remove code that has no effect

                    Remove the unused function parameter "$end".
                    Open

                        private function readFromPollerOutput($rrdfile, $cf, $start, $end, $dsnames, &$map, &$item)

                    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

                    Noncompliant Code Example

                    function doSomething($a, $b) { // "$a" is unused
                      return compute($b);
                    }
                    

                    Compliant Solution

                    function doSomething($b) {
                      return compute($b);
                    }
                    

                    Exceptions

                    Functions in classes that override a class or implement interfaces are ignored.

                    class C extends B {
                    
                      function doSomething($a, $b) {     // no issue reported on $b
                        compute($a);
                      }
                    
                    }
                    

                    See

                    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
                    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
                    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
                    • CERT, MSC12-CPP. - Detect and remove code that has no effect

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

                            MapUtility::debug("RRD ReadDataFromRealRRDAggregate: Returning (" . ($this->data[IN] === null ? 'null' : $this->data[IN]) . "," . ($this->data[OUT] === null ? 'null' : $this->data[OUT]) . ",$this->dataTime)\n");
                    Severity: Minor
                    Found in lib/Weathermap/Plugins/Datasources/RRDTool.php and 1 other location - About 40 mins to fix
                    lib/Weathermap/Plugins/Datasources/RRDTool.php on lines 432..432

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

                    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

                            MapUtility::debug("RRD ReadDataFromRealRRD: Returning (" . ($this->data[IN] === null ? 'null' : $this->data[IN]) . "," . ($this->data[OUT] === null ? 'null' : $this->data[OUT]) . ",$this->dataTime)\n");
                    Severity: Minor
                    Found in lib/Weathermap/Plugins/Datasources/RRDTool.php and 1 other location - About 40 mins to fix
                    lib/Weathermap/Plugins/Datasources/RRDTool.php on lines 307..307

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

                    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