howardjones/network-weathermap

View on GitHub
lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.php

Summary

Maintainability
D
2 days
Test Coverage

File WeatherMapCactiUserPlugin.php has 497 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Weathermap\Integrations\Cacti;

require_once dirname(__FILE__) . "/database.php";
Severity: Minor
Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.php - About 7 hrs to fix

    WeatherMapCactiUserPlugin has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WeatherMapCactiUserPlugin extends UIBase
    {
        /** @var MapManager $manager */
        public $manager;
        public $myURL;
    Severity: Minor
    Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.php - About 4 hrs to fix

      Method outputMapViewHeader has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function outputMapViewHeader($pageTitle, $isCycling, $limitingToGroup)
          {
              \html_start_box($pageTitle, '100%', '', '3', 'center', '');
              ?>
              <tr class="even">
      Severity: Minor
      Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.php - About 1 hr to fix

        Method handleDefaultView has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function handleDefaultView($request, $appObject)
            {
                global $wm_showOldUI, $config;
        
                $weathermapPath = $config['url_path'] . 'plugins/weathermap/';
        Severity: Minor
        Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.php - About 1 hr to fix

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

              public function handleSettingsAPI($request, $appObject)
              {
                  header('Content-type: application/json');
          
                  $styleTextOptions = array("thumbs", "full", "full-first-only");
          Severity: Minor
          Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.php - About 1 hr to fix

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

                private function drawOneFullMap($map)
                {
                    $htmlFileName = $this->outputDirectory . DIRECTORY_SEPARATOR . $map->filehash . ".html";
                    $mapTitle = $this->getMapTitle($map);
                    print '<div class="weathermapholder" id="mapholder_' . $map->filehash . '">';
            Severity: Minor
            Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.php - About 1 hr to fix

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

                  public function handleDefaultView($request, $appObject)
                  {
                      global $wm_showOldUI, $config;
              
                      $weathermapPath = $config['url_path'] . 'plugins/weathermap/';
              Severity: Minor
              Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.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 outputGroupTabs has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function outputGroupTabs($currentTab)
                  {
                      $tabs = $this->getValidTabs();
              
                      if (count($tabs) > 1) {
              Severity: Minor
              Found in lib/Weathermap/Integrations/Cacti/WeatherMapCactiUserPlugin.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

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

              class WeatherMapCactiUserPlugin 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.

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

                      'viewcycle_filtered' => array(

              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 "SHOULD-BE-OVERRIDDEN" 5 times.
              Open

                      $this->myURL = "SHOULD-BE-OVERRIDDEN";

              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 "Content-type: image/png" 3 times.
              Open

                      header('Content-type: image/png');

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

                      'maplist' => array('handler' => 'handleMapListAPI', 'args' => array()),

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

                          'args' => array(array("id", "maphash"), array("group_id", "int", true))

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

                      \html_start_box('Weathermap Info', '100%', '', '3', 'center', '');

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

                      if (isset($request['action'])) {

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

                      'viewthumb' => array(

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

                          'args' => array(array("id", "maphash"), array("time", "int", true))

              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.

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

                  public function makeURL($params, $altURL = "")
                  {
                      $baseURL = $this->myURL;
                      if ($altURL != "") {
                          $baseURL = $altURL;
              lib/Weathermap/Integrations/Cacti/WeatherMapCactiManagementPlugin.php on lines 229..244

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

              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