howardjones/network-weathermap

View on GitHub
lib/Weathermap/Editor/EditorUI.php

Summary

Maintainability
F
5 days
Test Coverage

File EditorUI.php has 910 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
// PHP Weathermap 0.97b
// Copyright Howard Jones, 2005-2012 howie@thingy.com
// http://www.network-weathermap.com/
// PHP Weathermap is licensed under the MIT License, see LICENSE file for more information.
Severity: Major
Found in lib/Weathermap/Editor/EditorUI.php - About 2 days to fix

    EditorUI has 52 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class EditorUI extends UIBase
    {
        private $editor;
    
        private $selected = "";
    Severity: Major
    Found in lib/Weathermap/Editor/EditorUI.php - About 7 hrs to fix

      Function getAvailableImages has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getAvailableImages($imageDirectory, $map)
          {
              $imageList = array();
      
              if (is_dir($imageDirectory)) {
      Severity: Minor
      Found in lib/Weathermap/Editor/EditorUI.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 showMainPage has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function showMainPage($editor)
          {
              global $hostPluginURL;
              global $hostEditorURL;
              global $hostType;
      Severity: Major
      Found in lib/Weathermap/Editor/EditorUI.php - About 2 hrs to fix

        Function main has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            public function main($request, $cookies, $fromPlugin = false)
            {
                $mapFileName = "";
                $action = "";
        
        
        Severity: Minor
        Found in lib/Weathermap/Editor/EditorUI.php - About 2 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 main has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function main($request, $cookies, $fromPlugin = false)
            {
                $mapFileName = "";
                $action = "";
        
        
        Severity: Minor
        Found in lib/Weathermap/Editor/EditorUI.php - About 1 hr to fix

          Method getAvailableImages has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getAvailableImages($imageDirectory, $map)
              {
                  $imageList = array();
          
                  if (is_dir($imageDirectory)) {
          Severity: Minor
          Found in lib/Weathermap/Editor/EditorUI.php - About 1 hr to fix

            Method getExistingConfigs has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getExistingConfigs($mapDirectory)
                {
                    $titles = array();
                    $notes = array();
            
            
            Severity: Minor
            Found in lib/Weathermap/Editor/EditorUI.php - About 1 hr to fix

              Method generateFontSampleImage has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function generateFontSampleImage($map)
                  {
                      $keyFontNumber = 2;
                      $keyFont = $map->fonts->getFont($keyFontNumber);
                      $keyHeight = imagefontheight($keyFontNumber) + 2;
              Severity: Minor
              Found in lib/Weathermap/Editor/EditorUI.php - About 1 hr to fix

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

                    public function getExistingConfigs($mapDirectory)
                    {
                        $titles = array();
                        $notes = array();
                
                
                Severity: Minor
                Found in lib/Weathermap/Editor/EditorUI.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

                Avoid deeply nested control flow statements.
                Open

                                        if ($size[0] > $this->minBGImageSize && $size[1] > $this->minBGImageSize) {
                                            $bg = true;
                                        }
                Severity: Major
                Found in lib/Weathermap/Editor/EditorUI.php - About 45 mins to fix

                  Function extractSettingsCookie has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function extractSettingsCookie($cookies)
                      {
                          // these are all set via the Editor Settings dialog, in the editor, now.
                  
                          $this->useOverlayVIA = false; // set to TRUE to enable experimental overlay showing VIAs
                  Severity: Minor
                  Found in lib/Weathermap/Editor/EditorUI.php - About 45 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 getTitleFromConfig has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static function getTitleFromConfig($filename, $defaultTitle = "")
                      {
                          $title = "";
                  
                          $fileHandle = fopen($filename, "r");
                  Severity: Minor
                  Found in lib/Weathermap/Editor/EditorUI.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 showMainPage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function showMainPage($editor)
                      {
                          global $hostPluginURL;
                          global $hostEditorURL;
                          global $hostType;
                  Severity: Minor
                  Found in lib/Weathermap/Editor/EditorUI.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 cmdDrawMap has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function cmdDrawMap($params, $editor)
                      {
                          header("Content-type: image/png");
                          // If the config file hasn't changed, then the image produced shouldn't have, either
                          $etag = md5_file($this->mapFileName);
                  Severity: Minor
                  Found in lib/Weathermap/Editor/EditorUI.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

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

                  class EditorUI extends UIBase

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

                      public function getAvailableImages($imageDirectory, $map)
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 21 to the 15 allowed.
                  Open

                      public function main($request, $cookies, $fromPlugin = false)
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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

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

                                  array("node_name", "name"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "selected" 4 times.
                  Open

                                  array("selected", "jsname", true), // optional
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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.

                  Rename "$mapFileName" which has the same name as the field declared at line 25.
                  Open

                          $mapFileName = "";

                  Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

                  Noncompliant Code Example

                  class Foo {
                    public $myField;
                  
                    public function doSomething() {
                      $myField = 0;
                      ...
                    }
                  }
                  

                  See

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

                                  array("map_stamp", "string"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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

                  //        $white = imagecolorallocate($fontsImageRef, 255, 255, 255);

                  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 unused "$ignoreCacti" private field.
                  Open

                      private $ignoreCacti = false;

                  If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.

                  Noncompliant Code Example

                  class MyClass {
                    private $foo = 4;                       //foo is unused
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  Compliant Solution

                  class MyClass {
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  See

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

                                  array("map_pngfile", "string"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "string" 23 times.
                  Open

                                  array("item_configtext", "string"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "no_save" 6 times.
                  Open

                              "no_save" => true
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "map_height" 4 times.
                  Open

                                  array("map_height", "int"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "mapfile" 31 times.
                  Open

                                  array("mapname", "mapfile"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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

                              // if ($this->isEmbedded()) {}

                  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 unused "$foundHost" private field.
                  Open

                      private $foundHost = false;

                  If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.

                  Noncompliant Code Example

                  class MyClass {
                    private $foo = 4;                       //foo is unused
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  Compliant Solution

                  class MyClass {
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  See

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

                                  array("link_name", "name"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "working" 32 times.
                  Open

                              "working" => true,
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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.

                  Rename "$selected" which has the same name as the field declared at line 24.
                  Open

                          $selected = 'NODE:' . $params['param'];

                  Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

                  Noncompliant Code Example

                  class Foo {
                    public $myField;
                  
                    public function doSomething() {
                      $myField = 0;
                      ...
                    }
                  }
                  

                  See

                  Rename "$editor" which has the same name as the field declared at line 22.
                  Open

                              $editor = new Editor();

                  Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

                  Noncompliant Code Example

                  class Foo {
                    public $myField;
                  
                    public function doSomething() {
                      $myField = 0;
                      ...
                    }
                  }
                  

                  See

                  Define a constant instead of duplicating this literal "handler" 30 times.
                  Open

                              "handler" => "cmdAddNode"
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "item_configtext" 4 times.
                  Open

                                  array("item_configtext", "string"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "item_type" 3 times.
                  Open

                                  array("item_type", "item_type"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "--NONE--" 3 times.
                  Open

                          if ($update['iconfilename'] == '--NONE--') {
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "map_bgfile" 4 times.
                  Open

                                  array("map_bgfile", "string"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 unused "$cactiBase" private field.
                  Open

                      private $cactiBase = "../..";

                  If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.

                  Noncompliant Code Example

                  class MyClass {
                    private $foo = 4;                       //foo is unused
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  Compliant Solution

                  class MyClass {
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  See

                  Remove this unused "$hostURL" private field.
                  Open

                      private $hostURL = "/";

                  If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.

                  Noncompliant Code Example

                  class MyClass {
                    private $foo = 4;                       //foo is unused
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  Compliant Solution

                  class MyClass {
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  See

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

                                  array("param2", "name"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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

                              "linklabels" => $editor->map->links['DEFAULT']->labelStyle,
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "HTTP_IF_NONE_MATCH" 4 times.
                  Open

                          if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 unused "$configError" private field.
                  Open

                      private $configError = "";

                  If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.

                  Noncompliant Code Example

                  class MyClass {
                    private $foo = 4;                       //foo is unused
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  Compliant Solution

                  class MyClass {
                  
                    public function compute($a) {
                      return $a * 4;
                    }
                  }
                  

                  See

                  Define a constant instead of duplicating this literal "mapname" 34 times.
                  Open

                                  array("mapname", "mapfile"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "map_width" 4 times.
                  Open

                                  array("map_width", "int"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "lock_to" 3 times.
                  Open

                              "lock_to" => $params['node_lock_to'],
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "map_htmlfile" 3 times.
                  Open

                                  array("map_htmlfile", "string"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "link_bandwidth_out_cb" 3 times.
                  Open

                                  array("link_bandwidth_out_cb", "string", true),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "param" 25 times.
                  Open

                                  array("param", "name")
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "late_load" 4 times.
                  Open

                              "late_load" => true,
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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

                  //        $whitekey = imagecolorallocate($keyImageRef, 255, 255, 255);

                  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 (substr($mapFileName, -5, 5) != '.conf' && strlen($mapFileName) > 0) {

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

                              "iconfilename" => $params['node_iconfilename']
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "wmeditor" 3 times.
                  Open

                          if (isset($cookies['wmeditor'])) {
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "reload_after_action" 3 times.
                  Open

                              "reload_after_action" => true,
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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 "link_width" 3 times.
                  Open

                                  array("link_width", "int"),
                  Severity: Critical
                  Found in lib/Weathermap/Editor/EditorUI.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.

                  There are no issues that match your filters.

                  Category
                  Status