howardjones/network-weathermap

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

Summary

Maintainability
F
1 wk
Test Coverage

File Map.php has 1266 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Weathermap\Core;

// PHP Weathermap 0.98
Severity: Major
Found in lib/Weathermap/Core/Map.php - About 3 days to fix

    Map has 63 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Map extends MapBase
    {
        /** @var MapNode[] $nodes */
        public $nodes = array();
        /** @var MapLink[] $links */
    Severity: Major
    Found in lib/Weathermap/Core/Map.php - About 1 day to fix

      Function calculateImagemap has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

          public function calculateImagemap()
          {
              MapUtility::debug("Trace: calculateImagemap()\n");
      
              // loop through everything. Figure out along the way if it's a node or a link
      Severity: Minor
      Found in lib/Weathermap/Core/Map.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

      Function getConfig has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getConfig()
          {
              $output = '';
      
              $output .= "# Automatically generated by php-weathermap v" . WEATHERMAP_VERSION . "\n\n";
      Severity: Minor
      Found in lib/Weathermap/Core/Map.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

      Function generateSortedImagemap has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          public function generateSortedImagemap($imagemapname)
          {
              $html = "\n<map name=\"" . $imagemapname . '" id="' . $imagemapname . "\">\n";
      
              $allLayers = array_keys($this->seenZLayers);
      Severity: Minor
      Found in lib/Weathermap/Core/Map.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 getConfig has 93 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getConfig()
          {
              $output = '';
      
              $output .= "# Automatically generated by php-weathermap v" . WEATHERMAP_VERSION . "\n\n";
      Severity: Major
      Found in lib/Weathermap/Core/Map.php - About 3 hrs to fix

        Function drawMap has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            public function drawMap(
                $imageFileName = '',
                $thumbnailFileName = '',
                $thumbnailMaxSize = 250,
                $includeNodes = true,
        Severity: Minor
        Found in lib/Weathermap/Core/Map.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 __construct has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function __construct()
            {
                parent::__construct();
        
                $this->inheritedFieldList = array
        Severity: Major
        Found in lib/Weathermap/Core/Map.php - About 2 hrs to fix

          Method calculateImagemap has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function calculateImagemap()
              {
                  MapUtility::debug("Trace: calculateImagemap()\n");
          
                  // loop through everything. Figure out along the way if it's a node or a link
          Severity: Minor
          Found in lib/Weathermap/Core/Map.php - About 1 hr to fix

            Method drawMap has 48 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function drawMap(
                    $imageFileName = '',
                    $thumbnailFileName = '',
                    $thumbnailMaxSize = 250,
                    $includeNodes = true,
            Severity: Minor
            Found in lib/Weathermap/Core/Map.php - About 1 hr to fix

              Function resolveRelativePositions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function resolveRelativePositions()
                  {
                      // calculate any relative positions here - that way, nothing else
                      // really needs to know about them
              
              
              Severity: Minor
              Found in lib/Weathermap/Core/Map.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 createThumbnailFile has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function createThumbnailFile($thumbnailFileName, $thumbnailMaxSize, $imageRef)
                  {
                      MapUtility::debug("Writing thumbnail to $thumbnailFileName\n");
              
                      if (!function_exists('imagecopyresampled')) {
              Severity: Minor
              Found in lib/Weathermap/Core/Map.php - About 1 hr to fix

                Method generateSortedImagemap has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function generateSortedImagemap($imagemapname)
                    {
                        $html = "\n<map name=\"" . $imagemapname . '" id="' . $imagemapname . "\">\n";
                
                        $allLayers = array_keys($this->seenZLayers);
                Severity: Minor
                Found in lib/Weathermap/Core/Map.php - About 1 hr to fix

                  Method resolveRelativePositions has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function resolveRelativePositions()
                      {
                          // calculate any relative positions here - that way, nothing else
                          // really needs to know about them
                  
                  
                  Severity: Minor
                  Found in lib/Weathermap/Core/Map.php - About 1 hr to fix

                    Function createThumbnailFile has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function createThumbnailFile($thumbnailFileName, $thumbnailMaxSize, $imageRef)
                        {
                            MapUtility::debug("Writing thumbnail to $thumbnailFileName\n");
                    
                            if (!function_exists('imagecopyresampled')) {
                    Severity: Minor
                    Found in lib/Weathermap/Core/Map.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 processStringToken has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function processStringToken($includeNotes, $keyContents, $key, $context)
                        {
                            $value = '[UNKNOWN]';
                            $format = "";
                            $theItem = null;
                    Severity: Minor
                    Found in lib/Weathermap/Core/Map.php - About 1 hr to fix

                      Method drawTimestamp has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function drawTimestamp($imageRef, $font, $colour, $which = '')
                          {
                              // add a timestamp to the corner, so we can tell if it's all being updated
                      
                              $fontObject = $this->fonts->getFont($font);
                      Severity: Minor
                      Found in lib/Weathermap/Core/Map.php - About 1 hr to fix

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

                            private function processStringFindReferredObject(&$context, $itemname, $type)
                            {
                                if (($itemname == "this") && ($type == strtolower($context->myType()))) {
                                    return $context;
                                }
                        Severity: Minor
                        Found in lib/Weathermap/Core/Map.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 buildOverlibHTML has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            private function buildOverlibHTML($mapItem, $dir, $imageExtraHTML, $left, $above, $caption)
                            {
                                $overlibhtml = "onmouseover=\"return overlib('";
                        
                                $n = 0;
                        Severity: Minor
                        Found in lib/Weathermap/Core/Map.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 drawMap has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                                $imageFileName = '',
                                $thumbnailFileName = '',
                                $thumbnailMaxSize = 250,
                                $includeNodes = true,
                                $showVIAOverlay = false,
                        Severity: Minor
                        Found in lib/Weathermap/Core/Map.php - About 45 mins to fix

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

                              private function buildOverlibHTML($mapItem, $dir, $imageExtraHTML, $left, $above, $caption)
                          Severity: Minor
                          Found in lib/Weathermap/Core/Map.php - About 45 mins to fix

                            Method buildOverlibPositioning has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                private function buildOverlibPositioning($mapItem, $midX, $mapCenterX, $midY, $mapCenterY)
                            Severity: Minor
                            Found in lib/Weathermap/Core/Map.php - About 35 mins to fix

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

                                  protected function drawViaOverlay($imageRef, $overlayColor)
                                  {
                                      foreach ($this->links as $link) {
                                          foreach ($link->viaList as $via) {
                                              if (isset($via[2])) {
                              Severity: Minor
                              Found in lib/Weathermap/Core/Map.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 writeImageFile has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  protected function writeImageFile($imageFileName, $imageRef)
                                  {
                                      $extension = strtolower(substr($imageFileName, -4, 4));
                              
                                      $types = array(
                              Severity: Minor
                              Found in lib/Weathermap/Core/Map.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

                              Avoid too many return statements within this method.
                              Open

                                          return $this->getLink($itemname);
                              Severity: Major
                              Found in lib/Weathermap/Core/Map.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return null;
                                Severity: Major
                                Found in lib/Weathermap/Core/Map.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return $this->getNode($itemname);
                                  Severity: Major
                                  Found in lib/Weathermap/Core/Map.php - About 30 mins to fix

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

                                        public function writeDataFile($filename)
                                        {
                                            if ($filename == '') {
                                                return;
                                            }
                                    Severity: Minor
                                    Found in lib/Weathermap/Core/Map.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 replicateLegendSettings has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private function replicateLegendSettings()
                                        {
                                            foreach ($this->legends as $scaleName => $legendObject) {
                                                // These are currently global settings for a map, not per-scale
                                                $legendObject->keyoutlinecolour = $this->colourtable['KEYOUTLINE'];
                                    Severity: Minor
                                    Found in lib/Weathermap/Core/Map.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 drawTimestamp has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private function drawTimestamp($imageRef, $font, $colour, $which = '')
                                        {
                                            // add a timestamp to the corner, so we can tell if it's all being updated
                                    
                                            $fontObject = $this->fonts->getFont($font);
                                    Severity: Minor
                                    Found in lib/Weathermap/Core/Map.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 processStringToken has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private function processStringToken($includeNotes, $keyContents, $key, $context)
                                        {
                                            $value = '[UNKNOWN]';
                                            $format = "";
                                            $theItem = null;
                                    Severity: Minor
                                    Found in lib/Weathermap/Core/Map.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 buildOverlibPositioning has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private function buildOverlibPositioning($mapItem, $midX, $mapCenterX, $midY, $mapCenterY)
                                        {
                                            $left = '';
                                            $above = '';
                                            $imageExtraHTML = '';
                                    Severity: Minor
                                    Found in lib/Weathermap/Core/Map.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 loadBackgroundImage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        protected function loadBackgroundImage()
                                        {
                                            $bgImageRef = null;
                                    
                                            // do the basic prep work
                                    Severity: Minor
                                    Found in lib/Weathermap/Core/Map.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

                                    Reduce the number of returns of this function 4, down to the maximum allowed 3.
                                    Open

                                        private function findItemValue(&$mapItem, $variableName, $currentValue, $includeNotes = true)
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

                                    Noncompliant Code Example

                                    With the default threshold of 3:

                                    function myFunction(){ // Noncompliant as there are 4 return statements
                                      if (condition1) {
                                        return true;
                                      } else {
                                        if (condition2) {
                                          return false;
                                        } else {
                                          return true;
                                        }
                                      }
                                      return false;
                                    }
                                    

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

                                        public function drawMap(
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    Class "Map" has 63 methods, which is greater than 20 authorized. Split it into smaller classes.
                                    Open

                                    class Map extends MapBase
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.

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

                                        private function resolveRelativePositions()
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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 31 to the 15 allowed.
                                    Open

                                        public function generateSortedImagemap($imagemapname)
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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 45 to the 15 allowed.
                                    Open

                                        public function calculateImagemap()
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    Reduce the number of returns of this function 7, down to the maximum allowed 3.
                                    Open

                                        private function processStringFindReferredObject(&$context, $itemname, $type)
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

                                    Noncompliant Code Example

                                    With the default threshold of 3:

                                    function myFunction(){ // Noncompliant as there are 4 return statements
                                      if (condition1) {
                                        return true;
                                      } else {
                                        if (condition2) {
                                          return false;
                                        } else {
                                          return true;
                                        }
                                      }
                                      return false;
                                    }
                                    

                                    Reduce the number of returns of this function 4, down to the maximum allowed 3.
                                    Open

                                        public function processString($input, &$context, $includeNotes = true, $multiline = false)
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

                                    Noncompliant Code Example

                                    With the default threshold of 3:

                                    function myFunction(){ // Noncompliant as there are 4 return statements
                                      if (condition1) {
                                        return true;
                                      } else {
                                        if (condition2) {
                                          return false;
                                        } else {
                                          return true;
                                        }
                                      }
                                      return false;
                                    }
                                    

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

                                        public function getConfig()
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    Remove this commented out code.
                                    Open

                                    //                        $html .= "\n";
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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"

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

                                                'title' => 'Network Weathermap',
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

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

                                                'KEYTEXT' => array('bottom' => -2, 'top' => -1, 'red' => 0, 'green' => 0, 'blue' => 0),
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    //    {
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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"

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

                                                'TITLE' => array('bottom' => -2, 'top' => -1, 'red' => 0, 'green' => 0, 'blue' => 0),
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

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

                                                'width' => 800,
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    //            $filename = '{text insert}';
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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"

                                    Merge this if statement with the enclosing one.
                                    Open

                                                            if ($template == $item->isTemplate()) {
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    Merging collapsible if statements increases the code's readability.

                                    Noncompliant Code Example

                                    if (condition1) {
                                      if (condition2) {
                                        ...
                                      }
                                    }
                                    

                                    Compliant Solution

                                    if (condition1 && condition2) {
                                      ...
                                    }
                                    

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

                                                'htmlstyle' => 'static',
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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 "DEFAULT" 17 times.
                                    Open

                                                'numscales' => array('DEFAULT' => 0),
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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 "direction" 5 times.
                                    Open

                                                            if (array_key_exists('direction', $area->info) and $area->info['direction'] == $dir) {
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    //        $theItem = null;
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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"

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

                                                'height' => 600,
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

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

                                                'stamptext' => 'Created: %b %d %Y %H:%M:%S',
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

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

                                            if ($this->context == 'editor') {
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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 ":: DEFAULT ::" 8 times.
                                    Open

                                            assert(is_object($this->nodes[":: DEFAULT ::"]));
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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 "bottom" 6 times.
                                    Open

                                                'KEYTEXT' => array('bottom' => -2, 'top' => -1, 'red' => 0, 'green' => 0, 'blue' => 0),
                                    Severity: Critical
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    //        MapUtility::debug("makeHTML ImageURI imagefile is '$this->imageoutputfile'");
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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

                                    //                        $html .= "\n";
                                    Severity: Major
                                    Found in lib/Weathermap/Core/Map.php by sonar-php

                                    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"

                                    There are no issues that match your filters.

                                    Category
                                    Status