howardjones/network-weathermap

View on GitHub
lib/Weathermap/Core/MapBase.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

    protected function getSimpleConfig($simpleParameters, $reference)
    {
        $output = '';
        foreach ($simpleParameters as $param) {
            $field = $param[0];
Severity: Minor
Found in lib/Weathermap/Core/MapBase.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

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

    public function getConfigValue($keyname)
    {
        if (isset($this->config[$keyname])) {
            return array($this->config[$keyname], self::CONF_FOUND_DIRECT);
        }
Severity: Minor
Found in lib/Weathermap/Core/MapBase.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

Function getHintConfig has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getHintConfig($comparison)
    {
        $output = '';
        foreach ($this->hints as $hintName => $hint) {
            // all hints for DEFAULT node are for writing
Severity: Minor
Found in lib/Weathermap/Core/MapBase.php - About 25 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

Function addConfigValue has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function addConfigValue($keyname, $value, $recalculate = false)
    {
        MapUtility::debug("Appending config %s = %s\n", $keyname, $value);
        if (is_null($this->config[$keyname])) {
            // create a new array, with this as the only item
Severity: Minor
Found in lib/Weathermap/Core/MapBase.php - About 25 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

Remove the code after this "throw".
Open

        throw new WeathermapUnimplementedException('Dynamic dependencies not implemented yet');
Severity: Major
Found in lib/Weathermap/Core/MapBase.php by sonar-php

Jump statements (return, break, continue, and goto) and throw expressions move control flow out of the current code block. Typically, any statements in a block that come after a jump or throw are simply wasted keystrokes lying in wait to confuse the unwary.

Rarely, as illustrated below, code after a jump or throw is reachable. However, such code is difficult to understand, and should be refactored.

Noncompliant Code Example

function fun($a) {
  $i = 10;
  return $i + $a;
  $i++;             // this is never executed
}

function foo($a) {
  if ($a == 5) {
    goto error;
  } else {
    // do the job
  }
  return;

  error:
    printf("don't use 5"); // this is reachable but unreadable

}

Compliant Solution

function fun($a) {
  $i = 10;
  return $i + $a;
}

function foo($a) {
  if ($a == 5) {
    handleError();
  } else {
    // do the job
  }
  return;
}

See

  • MISRA C:2004, 14.1 - There shall be no unreachable code
  • MISRA C++:2008, 0-1-1 - A project shall not contain unreachable code
  • MISRA C++:2008, 0-1-9 - There shall be no dead code
  • MISRA C:2012, 2.1 - A project shall not contain unreachable code
  • MISRA C:2012, 2.2 - There shall be no dead code
  • MITRE, CWE-561 - Dead Code
  • CERT, MSC56-J. - Detect and remove superfluous code and values
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC07-CPP. - Detect and remove dead code

There are no issues that match your filters.

Category
Status