modxcms/revolution

View on GitHub
core/model/modx/processors/element/getnodes.class.php

Summary

Maintainability
F
1 wk
Test Coverage

File getnodes.class.php has 521 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
 * This file is part of MODX Revolution.
 *
 * Copyright (c) MODX, LLC. All Rights Reserved.
Severity: Major
Found in core/model/modx/processors/element/getnodes.class.php - About 1 day to fix

    Function getInCategoryNodes has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getInCategoryNodes(array $map) {
            $nodes = array();
            /* 0: type,  1: element/category  2: elID  3: catID */
            $categoryId = isset($map[3]) ? $map[3] : ($map[1] == 'category' ? $map[2] : 0);
            $elementIdentifier = $map[0];
    Severity: Minor
    Found in core/model/modx/processors/element/getnodes.class.php - About 5 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

    Function getTypeNodes has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getTypeNodes(array $map) {
            $nodes = array();
            $elementType = ucfirst($map[1]);
            $elementClassKey = $this->typeMap[$map[1]];
    
    
    Severity: Minor
    Found in core/model/modx/processors/element/getnodes.class.php - About 5 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 getTypeNodes has 108 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getTypeNodes(array $map) {
            $nodes = array();
            $elementType = ucfirst($map[1]);
            $elementClassKey = $this->typeMap[$map[1]];
    
    
    Severity: Major
    Found in core/model/modx/processors/element/getnodes.class.php - About 4 hrs to fix

      Method getRootNodes has 104 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getRootNodes(array $map) {
              $elementType = ucfirst($map[0]);
              $nodes = array();
      
              /* Templates */
      Severity: Major
      Found in core/model/modx/processors/element/getnodes.class.php - About 4 hrs to fix

        Method getInCategoryNodes has 101 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getInCategoryNodes(array $map) {
                $nodes = array();
                /* 0: type,  1: element/category  2: elID  3: catID */
                $categoryId = isset($map[3]) ? $map[3] : ($map[1] == 'category' ? $map[2] : 0);
                $elementIdentifier = $map[0];
        Severity: Major
        Found in core/model/modx/processors/element/getnodes.class.php - About 4 hrs to fix

          Function getInCategoryElements has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getInCategoryElements(array $map)
              {
                  $nodes = array();
                  $elementIdentifier = $map[0];
                  $categoryId = $map[1];
          Severity: Minor
          Found in core/model/modx/processors/element/getnodes.class.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 getCategoryNodes has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getCategoryNodes(array $map)
              {
                  if (!empty($map[1])) {
                      /* if grabbing subcategories */
                      $c = $this->modx->newQuery('modCategory');
          Severity: Major
          Found in core/model/modx/processors/element/getnodes.class.php - About 2 hrs to fix

            Function getCategoryNodes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getCategoryNodes(array $map)
                {
                    if (!empty($map[1])) {
                        /* if grabbing subcategories */
                        $c = $this->modx->newQuery('modCategory');
            Severity: Minor
            Found in core/model/modx/processors/element/getnodes.class.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 getInCategoryElements has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getInCategoryElements(array $map)
                {
                    $nodes = array();
                    $elementIdentifier = $map[0];
                    $categoryId = $map[1];
            Severity: Minor
            Found in core/model/modx/processors/element/getnodes.class.php - About 1 hr to fix

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

                  protected function subCategoriesHaveElements($categoryId, $elementClassKey) {
                      $return = false;
              
                      $categories = $this->modx->getCollection('modCategory', array(
                          'parent' => $categoryId
              Severity: Minor
              Found in core/model/modx/processors/element/getnodes.class.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

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

                  public function getRootNodes(array $map) {
                      $elementType = ucfirst($map[0]);
                      $nodes = array();
              
                      /* Templates */
              Severity: Minor
              Found in core/model/modx/processors/element/getnodes.class.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

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

                      if ($this->modx->hasPermission('view_snippet')) {
                          $class = $this->modx->hasPermission('new_snippet') ? ' pnew' : '';
                          $class .= $this->modx->hasPermission('new_category') ? ' pnewcat' : '';
                          $class .= ' tree-pseudoroot-node';
              
              
              Severity: Major
              Found in core/model/modx/processors/element/getnodes.class.php and 4 other locations - About 3 hrs to fix
              core/model/modx/processors/element/getnodes.class.php on lines 111..128
              core/model/modx/processors/element/getnodes.class.php on lines 131..148
              core/model/modx/processors/element/getnodes.class.php on lines 151..168
              core/model/modx/processors/element/getnodes.class.php on lines 191..208

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

              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

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

                      if ($this->modx->hasPermission('view_chunk')) {
                          $class = $this->modx->hasPermission('new_chunk') ? ' pnew' : '';
                          $class .= $this->modx->hasPermission('new_category') ? ' pnewcat' : '';
                          $class .= ' tree-pseudoroot-node';
              
              
              Severity: Major
              Found in core/model/modx/processors/element/getnodes.class.php and 4 other locations - About 3 hrs to fix
              core/model/modx/processors/element/getnodes.class.php on lines 111..128
              core/model/modx/processors/element/getnodes.class.php on lines 131..148
              core/model/modx/processors/element/getnodes.class.php on lines 171..188
              core/model/modx/processors/element/getnodes.class.php on lines 191..208

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

              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

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

                      if ($this->modx->hasPermission('view_template')) {
                          $class = $this->modx->hasPermission('new_template') ? ' pnew' : '';
                          $class .= $this->modx->hasPermission('new_category') ? ' pnewcat' : '';
                          $class .= ' tree-pseudoroot-node';
              
              
              Severity: Major
              Found in core/model/modx/processors/element/getnodes.class.php and 4 other locations - About 3 hrs to fix
              core/model/modx/processors/element/getnodes.class.php on lines 131..148
              core/model/modx/processors/element/getnodes.class.php on lines 151..168
              core/model/modx/processors/element/getnodes.class.php on lines 171..188
              core/model/modx/processors/element/getnodes.class.php on lines 191..208

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

              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

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

                      if ($this->modx->hasPermission('view_plugin')) {
                          $class = $this->modx->hasPermission('new_snippet') ? ' pnew' : '';
                          $class .= $this->modx->hasPermission('new_category') ? ' pnewcat' : '';
                          $class .= ' tree-pseudoroot-node';
              
              
              Severity: Major
              Found in core/model/modx/processors/element/getnodes.class.php and 4 other locations - About 3 hrs to fix
              core/model/modx/processors/element/getnodes.class.php on lines 111..128
              core/model/modx/processors/element/getnodes.class.php on lines 131..148
              core/model/modx/processors/element/getnodes.class.php on lines 151..168
              core/model/modx/processors/element/getnodes.class.php on lines 171..188

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

              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

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

                      if ($this->modx->hasPermission('view_tv')) {
                          $class = $this->modx->hasPermission('new_tv') ? ' pnew' : '';
                          $class .= $this->modx->hasPermission('new_category') ? ' pnewcat' : '';
                          $class .= ' tree-pseudoroot-node';
              
              
              Severity: Major
              Found in core/model/modx/processors/element/getnodes.class.php and 4 other locations - About 3 hrs to fix
              core/model/modx/processors/element/getnodes.class.php on lines 111..128
              core/model/modx/processors/element/getnodes.class.php on lines 151..168
              core/model/modx/processors/element/getnodes.class.php on lines 171..188
              core/model/modx/processors/element/getnodes.class.php on lines 191..208

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

              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