howardjones/network-weathermap

View on GitHub
lib/Weathermap/Tests/EditorTest.php

Summary

Maintainability
C
1 day
Test Coverage

File EditorTest.php has 393 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
//
//require_once dirname(__FILE__) . '/../lib/all.php';
//require_once dirname(__FILE__) . '/../lib/Editor.php';
//include_once dirname(__FILE__) . "/WMTestSupport.php";
Severity: Minor
Found in lib/Weathermap/Tests/EditorTest.php - About 5 hrs to fix

    Method testLinkProperties has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function testLinkProperties()
        {
            $editor = new Editor();
            $editor->newConfig();
    
    
    Severity: Major
    Found in lib/Weathermap/Tests/EditorTest.php - About 2 hrs to fix

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

          public function testNodeProperties()
          {
              $editor = new Editor();
              $editor->newConfig();
      
      
      Severity: Minor
      Found in lib/Weathermap/Tests/EditorTest.php - About 1 hr to fix

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

            public function testTidy()
            {
                $editor = new Editor();
                $editor->newConfig();
        
        
        Severity: Minor
        Found in lib/Weathermap/Tests/EditorTest.php - About 1 hr to fix

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

              public function testTidyAll()
              {
                  $editor = new Editor();
                  $editor->newConfig();
          
          
          Severity: Minor
          Found in lib/Weathermap/Tests/EditorTest.php - About 1 hr to fix

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

                public function testTidyAll()
                {
                    $editor = new Editor();
                    $editor->newConfig();
            
            
            Severity: Minor
            Found in lib/Weathermap/Tests/EditorTest.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

            Define a constant instead of duplicating this literal "named_node" 43 times.
            Open

                    $editor->addNode(100, 100, "named_node");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "node4" 4 times.
            Open

                    $editor->addNode(200, 298, "node4");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "gazorpazorpfield" 3 times.
            Open

                    $editor->renameLink("linky", "gazorpazorpfield");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "makeString" 4 times.
            Open

                    $nDepsString = join(" ", array_map(array("Weathermap\\Tests\\EditorTest", "makeString"), $nDeps));
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "node3" 11 times.
            Open

                    $newName = $editor->renameNode("traflorkians", "node3");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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

            //require_once dirname(__FILE__) . '/../lib/all.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 "node5" 6 times.
            Open

                    $editor->addNode(200, 402, "node5");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "steve" 8 times.
            Open

                    $newName = $editor->renameNode("named_node", "steve");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "node1" 17 times.
            Open

                    $editor->addNode(100, 100, "node1");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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

            //        $this->assertEquals(250, $n2->x);

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

                    $editor->addLink("other_named_node", "named_node", "linky");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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" 6 times.
            Open

                        "lock_to" => '',
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "node2" 14 times.
            Open

                    $editor->addNode(100, 200, "node2");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "other_named_node" 19 times.
            Open

                    $editor->addNode(100, 200, "other_named_node");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "infourl" 3 times.
            Open

                        "infourl" => '',
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "Weathermap\Tests\EditorTest" 4 times.
            Open

                    $nDepsString = join(" ", array_map(array("Weathermap\\Tests\\EditorTest", "makeString"), $nDeps));
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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

            //            "Dependency created for relative positioning");

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

                    $editor->addNode(200, 100, "node6");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "named_link" 8 times.
            Open

                    $editor->addLink("named_node", "third_named_node", "named_link");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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

            //        $nDeps = $n1->getDependencies();

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

                        if ($link->name != ":: DEFAULT ::" && $link->name != "DEFAULT") {
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "third_named_node" 18 times.
            Open

                    $editor->addNode(200, 200, "third_named_node", "named_node");
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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 "hover" 3 times.
            Open

                        "hover" => '',
            Severity: Critical
            Found in lib/Weathermap/Tests/EditorTest.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