luyadev/luya-module-cms

View on GitHub
src/models/Nav.php

Summary

Maintainability
F
4 days
Test Coverage
F
19%

File Nav.php has 595 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace luya\cms\models;

use luya\admin\models\Group;
Severity: Major
Found in src/models/Nav.php - About 1 day to fix

    Nav has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Nav extends ActiveRecord
    {
        use TaggableTrait;
    
        /**
    Severity: Minor
    Found in src/models/Nav.php - About 4 hrs to fix

      Method createPageFromDraft has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false): bool|array
          {
              if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) {
                  $isDraft = 0;
              }
      Severity: Major
      Found in src/models/Nav.php - About 2 hrs to fix

        Method createPage has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false): array|int
            {
                $_errors = [];
        
                $nav = $this;
        Severity: Minor
        Found in src/models/Nav.php - About 1 hr to fix

          Method createRedirect has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function createRedirect($parentNavId, $navContainerId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget, $anchor = null): array|int
              {
                  $_errors = [];
          
                  $nav = $this;
          Severity: Minor
          Found in src/models/Nav.php - About 1 hr to fix

            Method createModule has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function createModule($parentNavId, $navContainerId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
                {
                    $_errors = [];
            
                    $nav = $this;
            Severity: Minor
            Found in src/models/Nav.php - About 1 hr to fix

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

                  public function createPageItem($navId, $langId, $title, $alias, $layoutId, $description): array|int
                  {
                      $_errors = [];
              
                      $navItem = new NavItem();
              Severity: Minor
              Found in src/models/Nav.php - About 1 hr to fix

                Method createModule has 10 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public function createModule($parentNavId, $navContainerId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
                Severity: Major
                Found in src/models/Nav.php - About 1 hr to fix

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

                      public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false): bool|array
                      {
                          if (!$isDraft && empty($isDraft) && !is_numeric($isDraft)) {
                              $isDraft = 0;
                          }
                  Severity: Minor
                  Found in src/models/Nav.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 createRedirect has 10 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public function createRedirect($parentNavId, $navContainerId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget, $anchor = null): array|int
                  Severity: Major
                  Found in src/models/Nav.php - About 1 hr to fix

                    Method createModuleItem has 9 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public function createModuleItem($navId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
                    Severity: Major
                    Found in src/models/Nav.php - About 1 hr to fix

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

                          public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget): array|int
                          {
                              $_errors = [];
                      
                              $navItem = new NavItem();
                      Severity: Minor
                      Found in src/models/Nav.php - About 1 hr to fix

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

                            public function createModuleItem($navId, $langId, $title, $alias, $moduleName, $description, $controllerName, $actionName, array $actionParams): array|int
                            {
                                $_errors = [];
                        
                                $navItem = new NavItem();
                        Severity: Minor
                        Found in src/models/Nav.php - About 1 hr to fix

                          Method createPageFromDraft has 8 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public function createPageFromDraft($parentNavId, $navContainerId, $langId, $title, $alias, $description, $fromDraftNavId, $isDraft = false): bool|array
                          Severity: Major
                          Found in src/models/Nav.php - About 1 hr to fix

                            Method createPage has 8 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false): array|int
                            Severity: Major
                            Found in src/models/Nav.php - About 1 hr to fix

                              Method createRedirectItem has 8 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget): array|int
                              Severity: Major
                              Found in src/models/Nav.php - About 1 hr to fix

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

                                    public function createPageItem($navId, $langId, $title, $alias, $layoutId, $description): array|int
                                Severity: Minor
                                Found in src/models/Nav.php - About 45 mins to fix

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

                                      public static function checkDuplicateAlias($currentNavId, $parentNavId)
                                      {
                                          $currentNavItems = NavItem::find()->where(['nav_id' => $currentNavId])->asArray()->all();
                                          foreach (self::find()->where(['parent_nav_id' => $parentNavId, 'is_deleted' => false])->andWhere(['<>', 'id', $currentNavId])->asArray()->all() as $item) {
                                              foreach ($currentNavItems as $currentNavItem) {
                                  Severity: Minor
                                  Found in src/models/Nav.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

                                  Avoid too many return statements within this method.
                                  Open

                                          return $sourceNavItem->copyTypeContent($navItem);
                                  Severity: Major
                                  Found in src/models/Nav.php - About 30 mins to fix

                                    Function createPage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public function createPage($parentNavId, $navContainerId, $langId, $title, $alias, $layoutId, $description, $isDraft = false): array|int
                                        {
                                            $_errors = [];
                                    
                                            $nav = $this;
                                    Severity: Minor
                                    Found in src/models/Nav.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

                                    There are no issues that match your filters.

                                    Category
                                    Status