GemsTracker/gemstracker-library

View on GitHub
classes/Gems/Menu.php

Summary

Maintainability
F
4 days
Test Coverage
C
76%

File Menu.php has 726 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * @package    Gems
 * @subpackage Menu
Severity: Major
Found in classes/Gems/Menu.php - About 1 day to fix

    Method addRespondentPage has 248 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function addRespondentPage($label)
        {
            $orgId = $this->currentUser->getCurrentOrganizationId();
    
            $params = array(\MUtil_Model::REQUEST_ID1  => 'gr2o_patient_nr', \MUtil_Model::REQUEST_ID2 => 'gr2o_id_organization');
    Severity: Major
    Found in classes/Gems/Menu.php - About 1 day to fix

      Gems_Menu has 39 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Gems_Menu extends \Gems_Menu_MenuAbstract implements \MUtil_Html_HtmlInterface
      {
          /**
           *
           * @var \Gems_Menu_SubMenuItem
      Severity: Minor
      Found in classes/Gems/Menu.php - About 5 hrs to fix

        The class Gems_Menu has 26 non-getter- and setter-methods. Consider refactoring Gems_Menu to keep number of methods under 25.
        Open

        class Gems_Menu extends \Gems_Menu_MenuAbstract implements \MUtil_Html_HtmlInterface
        {
            /**
             *
             * @var \Gems_Menu_SubMenuItem
        Severity: Minor
        Found in classes/Gems/Menu.php by phpmd

        TooManyMethods

        Since: 0.1

        A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

        By default it ignores methods starting with 'get' or 'set'.

        The default was changed from 10 to 25 in PHPMD 2.3.

        Example

        Source https://phpmd.org/rules/codesize.html#toomanymethods

        The class Gems_Menu has an overall complexity of 90 which is very high. The configured complexity threshold is 50.
        Open

        class Gems_Menu extends \Gems_Menu_MenuAbstract implements \MUtil_Html_HtmlInterface
        {
            /**
             *
             * @var \Gems_Menu_SubMenuItem
        Severity: Minor
        Found in classes/Gems/Menu.php by phpmd

        The class Gems_Menu has 22 public methods. Consider refactoring Gems_Menu to keep number of public methods under 10.
        Open

        class Gems_Menu extends \Gems_Menu_MenuAbstract implements \MUtil_Html_HtmlInterface
        {
            /**
             *
             * @var \Gems_Menu_SubMenuItem
        Severity: Minor
        Found in classes/Gems/Menu.php by phpmd

        TooManyPublicMethods

        Since: 0.1

        A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

        By default it ignores methods starting with 'get' or 'set'.

        Example

        Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

        Function renderItems has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function renderItems(\MUtil_Html_ListElement $ul, array $items, $cascade)
            {
                foreach ($items as $item) {
                    if (isset($item['visible'], $item['label']) && $item['visible'] && $item['label']) {
                        $url = $item['params'];
        Severity: Minor
        Found in classes/Gems/Menu.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 addHiddenPrivileges has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function addHiddenPrivileges()
            {
                // Privileges not associated with menu item
                $this->addHiddenPrivilege('pr.organization-switch', $this->_(
                        'Grant access to all organization.'
        Severity: Major
        Found in classes/Gems/Menu.php - About 2 hrs to fix

          Method addGemsSetupContainer has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function addGemsSetupContainer($label)
              {
                  $setup = $this->addContainer($label);
          
                  // PROJECT LEVEL
          Severity: Minor
          Found in classes/Gems/Menu.php - About 2 hrs to fix

            Method toActiveBranchElement has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function toActiveBranchElement()
                {
                    $request    = $this->_getOriginalRequest();
                    $activePath = $this->_findPath($request);
            
            
            Severity: Minor
            Found in classes/Gems/Menu.php - About 1 hr to fix

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

                  public function toActiveBranchElement()
                  {
                      $request    = $this->_getOriginalRequest();
                      $activePath = $this->_findPath($request);
              
              
              Severity: Minor
              Found in classes/Gems/Menu.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

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

                  public function getCurrentMenuList(\Zend_Controller_Request_Abstract $request, $parentLabel = null)
                  {
                      $controller = $request->getControllerName();
                      $action     = $request->getActionName();
              
              
              Severity: Minor
              Found in classes/Gems/Menu.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 addRespondentPage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function addRespondentPage($label)
                  {
                      $orgId = $this->currentUser->getCurrentOrganizationId();
              
                      $params = array(\MUtil_Model::REQUEST_ID1  => 'gr2o_patient_nr', \MUtil_Model::REQUEST_ID2 => 'gr2o_id_organization');
              Severity: Minor
              Found in classes/Gems/Menu.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

              The class Gems_Menu has 1143 lines of code. Current threshold is 1000. Avoid really long classes.
              Open

              class Gems_Menu extends \Gems_Menu_MenuAbstract implements \MUtil_Html_HtmlInterface
              {
                  /**
                   *
                   * @var \Gems_Menu_SubMenuItem
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              The method addRespondentPage() has 297 lines of code. Current threshold is set to 100. Avoid really long methods.
              Open

                  public function addRespondentPage($label)
                  {
                      $orgId = $this->currentUser->getCurrentOrganizationId();
              
                      $params = array(\MUtil_Model::REQUEST_ID1  => 'gr2o_patient_nr', \MUtil_Model::REQUEST_ID2 => 'gr2o_id_organization');
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              The method renderItems() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
              Open

                  protected function renderItems(\MUtil_Html_ListElement $ul, array $items, $cascade)
                  {
                      foreach ($items as $item) {
                          if (isset($item['visible'], $item['label']) && $item['visible'] && $item['label']) {
                              $url = $item['params'];
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              CyclomaticComplexity

              Since: 0.1

              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

              Example

              // Cyclomatic Complexity = 11
              class Foo {
              1   public function example() {
              2       if ($a == $b) {
              3           if ($a1 == $b1) {
                              fiddle();
              4           } elseif ($a2 == $b2) {
                              fiddle();
                          } else {
                              fiddle();
                          }
              5       } elseif ($c == $d) {
              6           while ($c == $d) {
                              fiddle();
                          }
              7        } elseif ($e == $f) {
              8           for ($n = 0; $n < $h; $n++) {
                              fiddle();
                          }
                      } else {
                          switch ($z) {
              9               case 1:
                                  fiddle();
                                  break;
              10              case 2:
                                  fiddle();
                                  break;
              11              case 3:
                                  fiddle();
                                  break;
                              default:
                                  fiddle();
                                  break;
                          }
                      }
                  }
              }

              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

              The class Gems_Menu has a coupling between objects value of 22. Consider to reduce the number of dependencies under 13.
              Open

              class Gems_Menu extends \Gems_Menu_MenuAbstract implements \MUtil_Html_HtmlInterface
              {
                  /**
                   *
                   * @var \Gems_Menu_SubMenuItem
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              CouplingBetweenObjects

              Since: 1.1.0

              A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

              Example

              class Foo {
                  /**
                   * @var \foo\bar\X
                   */
                  private $x = null;
              
                  /**
                   * @var \foo\bar\Y
                   */
                  private $y = null;
              
                  /**
                   * @var \foo\bar\Z
                   */
                  private $z = null;
              
                  public function setFoo(\Foo $foo) {}
                  public function setBar(\Bar $bar) {}
                  public function setBaz(\Baz $baz) {}
              
                  /**
                   * @return \SplObjectStorage
                   * @throws \OutOfRangeException
                   * @throws \InvalidArgumentException
                   * @throws \ErrorException
                   */
                  public function process(\Iterator $it) {}
              
                  // ...
              }

              Source https://phpmd.org/rules/design.html#couplingbetweenobjects

              Avoid unused local variables such as '$item'.
              Open

                      foreach ($nav as $item => $sub) {
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              UnusedLocalVariable

              Since: 0.2

              Detects when a local variable is declared and/or assigned, but not used.

              Example

              class Foo {
                  public function doSomething()
                  {
                      $i = 5; // Unused
                  }
              }

              Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

              Avoid excessively long variable names like $_onlyActiveBranchVisible. Keep variable name length under 20.
              Open

                  private $_onlyActiveBranchVisible = false;
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              LongVariable

              Since: 0.2

              Detects when a field, formal or local variable is declared with a long name.

              Example

              class Something {
                  protected $reallyLongIntName = -3; // VIOLATION - Field
                  public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                      $otherReallyLongName = -5; // VIOLATION - Local
                      for ($interestingIntIndex = 0; // VIOLATION - For
                           $interestingIntIndex < 10;
                           $interestingIntIndex++ ) {
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#longvariable

              Avoid variables with short names like $ul. Configured minimum length is 3.
              Open

                  protected function renderItems(\MUtil_Html_ListElement $ul, array $items, $cascade)
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              Avoid variables with short names like $ul. Configured minimum length is 3.
              Open

                      $ul = $this->renderFirst();
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              Avoid variables with short names like $a. Configured minimum length is 3.
              Open

                              $a = $li->a($url, $item['label']);
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              Avoid variables with short names like $ul. Configured minimum length is 3.
              Open

                      $ul = $this->renderFirst();
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              Avoid variables with short names like $li. Configured minimum length is 3.
              Open

                              $li = $ul->li();
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              Avoid variables with short names like $ul. Configured minimum length is 3.
              Open

                      $ul = $this->renderFirst();
              Severity: Minor
              Found in classes/Gems/Menu.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              There are no issues that match your filters.

              Category
              Status