howardjones/network-weathermap

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

Summary

Maintainability
F
5 days
Test Coverage

File MapLink.php has 643 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
// PHP Weathermap 0.98
// Copyright Howard Jones, 2005-2016 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/Core/MapLink.php - About 1 day to fix

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

        public function getConfig()
        {
            if ($this->configOverride != '') {
                return $this->configOverride . "\n";
            }
    Severity: Minor
    Found in lib/Weathermap/Core/MapLink.php - About 7 hrs to fix

    Cognitive Complexity

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

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

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

    Further reading

    Method getConfig has 137 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getConfig()
        {
            if ($this->configOverride != '') {
                return $this->configOverride . "\n";
            }
    Severity: Major
    Found in lib/Weathermap/Core/MapLink.php - About 5 hrs to fix

      MapLink has 24 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class MapLink extends MapDataItem
      {
          const FMT_BITS_IN = '{link:this:bandwidth_in:%2k}';
          const FMT_BITS_OUT = '{link:this:bandwidth_out:%2k}';
          const FMT_UNFORM_IN = '{link:this:bandwidth_in}';
      Severity: Minor
      Found in lib/Weathermap/Core/MapLink.php - About 2 hrs to fix

        Method drawLabelRotated has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function drawLabelRotated($imageRef, $centre, $degreesAngle, $text, $padding, $direction)
            {
                $fontObject = $this->owner->fonts->getFont($this->bwfont);
                list($strWidth, $strHeight) = $fontObject->calculateImageStringSize($text);
        
        
        Severity: Major
        Found in lib/Weathermap/Core/MapLink.php - About 2 hrs to fix

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

              public function __construct($name, $template, $owner)
              {
                  parent::__construct();
          
                  $this->name = $name;
          Severity: Minor
          Found in lib/Weathermap/Core/MapLink.php - About 1 hr to fix

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

                public function preCalculate(&$map)
                {
                    MapUtility::debug('Link ' . $this->name . ": Calculating geometry.\n");
            
                    // don't bother doing anything if it's a template
            Severity: Minor
            Found in lib/Weathermap/Core/MapLink.php - About 1 hr to fix

              Method editorData has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function editorData()
                  {
                      $newOutput = array(
                          "id" => "L" . $this->id,
                          "name" => $this->name,
              Severity: Minor
              Found in lib/Weathermap/Core/MapLink.php - About 1 hr to fix

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

                    private function calculateCommentPosition($fontObject, $comment, $direction, $widthList)
                    {
                        list($textWidth, $textHeight) = $fontObject->calculateImageStringSize($comment);
                
                        // nudge pushes the comment out along the link arrow a little bit
                Severity: Minor
                Found in lib/Weathermap/Core/MapLink.php - About 1 hr to fix

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

                      private function drawBandwidthLabels($gdImage)
                      {
                          MapUtility::debug('Link ' . $this->name . ": Drawing bwlabels.\n");
                  
                          $directions = $this->getDirectionList();
                  Severity: Minor
                  Found in lib/Weathermap/Core/MapLink.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 drawBandwidthLabels has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function drawBandwidthLabels($gdImage)
                      {
                          MapUtility::debug('Link ' . $this->name . ": Drawing bwlabels.\n");
                  
                          $directions = $this->getDirectionList();
                  Severity: Minor
                  Found in lib/Weathermap/Core/MapLink.php - About 1 hr to fix

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

                        public function preCalculate(&$map)
                        {
                            MapUtility::debug('Link ' . $this->name . ": Calculating geometry.\n");
                    
                            // don't bother doing anything if it's a template
                    Severity: Minor
                    Found in lib/Weathermap/Core/MapLink.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 calculateCommentPosition has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function calculateCommentPosition($fontObject, $comment, $direction, $widthList)
                        {
                            list($textWidth, $textHeight) = $fontObject->calculateImageStringSize($comment);
                    
                            // nudge pushes the comment out along the link arrow a little bit
                    Severity: Minor
                    Found in lib/Weathermap/Core/MapLink.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

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

                        private function drawLabelRotated($imageRef, $centre, $degreesAngle, $text, $padding, $direction)
                    Severity: Minor
                    Found in lib/Weathermap/Core/MapLink.php - About 45 mins to fix

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

                          public function setEndNodes($node1, $node2)
                          {
                              if (null !== $node1 && null === $node2) {
                                  throw new WeathermapInternalFail('PartiallyRealLink');
                              }
                      Severity: Minor
                      Found in lib/Weathermap/Core/MapLink.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 drawComments has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private function drawComments($gdImage)
                          {
                              MapUtility::debug('Link ' . $this->name . ": Drawing comments.\n");
                      
                              $directions = $this->getDirectionList();
                      Severity: Minor
                      Found in lib/Weathermap/Core/MapLink.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

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

                          public function getConfig()
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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 "MapLink" has 24 methods, which is greater than 20 authorized. Split it into smaller classes.
                      Open

                      class MapLink extends MapDataItem
                      Severity: Major
                      Found in lib/Weathermap/Core/MapLink.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.

                      This function "getConfig" has 180 lines, which is greater than the 150 lines authorized. Split it into smaller functions.
                      Open

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

                      A function that grows too large tends to aggregate too many responsibilities.

                      Such functions inevitably become harder to understand and therefore harder to maintain.

                      Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.

                      Those smaller functions will not only be easier to understand, but also probably easier to test.

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

                                  'width' => 7,
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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 "percent" 3 times.
                      Open

                                  'scaletype' => 'percent',
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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 "overlibwidth" 3 times.
                      Open

                                  'overlibwidth' => 0,
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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("Format for direction=" . $this->bwlabelformats[$direction] . "\n");
                      Severity: Major
                      Found in lib/Weathermap/Core/MapLink.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 "zorder" 3 times.
                      Open

                                  'zorder' => 300,
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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 " 7 times.
                      Open

                              MapUtility::debug('Link ' . $this->name . ": Drawing comments.\n");
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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 "POINTS SO FAR:" 3 times.
                      Open

                              MapUtility::debug('POINTS SO FAR:' . join(' ', $points) . "\n");
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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 "overlibheight" 3 times.
                      Open

                                  'overlibheight' => 0,
                      Severity: Critical
                      Found in lib/Weathermap/Core/MapLink.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.

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

                              $translations = array(
                                  'inscalekey' => $this->scaleKeys[IN],
                                  'outscalekey' => $this->scaleKeys[OUT],
                                  "inscaletag" => $this->scaleTags[IN],
                                  "outscaletag" => $this->scaleTags[OUT],
                      Severity: Major
                      Found in lib/Weathermap/Core/MapLink.php and 1 other location - About 5 hrs to fix
                      lib/Weathermap/Core/MapNode.php on lines 1292..1306

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 183.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      There are no issues that match your filters.

                      Category
                      Status