divio/django-cms

View on GitHub
cms/cms_menus.py

Summary

Maintainability
F
3 days
Test Coverage

Function modify has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

    def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
        if post_cut:
            return nodes
        # rearrange the parent relations
        # Find home
Severity: Minor
Found in cms/cms_menus.py - About 7 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

File cms_menus.py has 359 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
from django.db.models.query import Prefetch, prefetch_related_objects
from django.urls import reverse
from django.utils.functional import SimpleLazyObject
from django.utils.translation import override as force_language
Severity: Minor
Found in cms/cms_menus.py - About 4 hrs to fix

    Function get_menu_node_for_page has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_menu_node_for_page(renderer, page, language, fallbacks=None):
        """
        Transform a CMS page into a navigation node.
    
        :param renderer: MenuRenderer instance bound to the request
    Severity: Minor
    Found in cms/cms_menus.py - About 3 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 get_nodes has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_nodes(self, request):
            from cms.models import Title
    
            site = self.renderer.site
            lang = self.renderer.request_language
    Severity: Minor
    Found in cms/cms_menus.py - 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

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

    def get_visible_nodes(request, pages, site):
        """
         This code is basically a many-pages-at-once version of
         cms.utils.page_permissions.user_can_view_page
         pages contains all published pages
    Severity: Minor
    Found in cms/cms_menus.py - 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

    Function find_ancestors_and_remove_children has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def find_ancestors_and_remove_children(self, node, nodes):
            """
            Check ancestors of node for soft roots
            """
            if node.parent:
    Severity: Minor
    Found in cms/cms_menus.py - 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 modify has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
            # only apply this modifier if we're pre-cut (since what we do is cut)
            # or if no id argument is provided, indicating {% show_menu_below_id %}
            if post_cut or root_id:
                return nodes
    Severity: Minor
    Found in cms/cms_menus.py - 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

    Avoid deeply nested control flow statements.
    Open

                            if extnode.namespace == ext and not extnode.parent_id:
                                # if home has nav extenders but home is not visible
                                if node == home and not node.visible:
                                    # extnode.parent_id = None
                                    extnode.parent_namespace = None
    Severity: Major
    Found in cms/cms_menus.py - About 45 mins to fix

      Function modify has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
      Severity: Minor
      Found in cms/cms_menus.py - About 45 mins to fix

        Function modify has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
        Severity: Minor
        Found in cms/cms_menus.py - About 45 mins to fix

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

                  if is_valid_site_language(lang, site_id=site.pk):
                      _valid_language = True
                      _hide_untranslated = hide_untranslated(lang, site.pk)
                  else:
                      _valid_language = False
          Severity: Major
          Found in cms/cms_menus.py and 1 other location - About 1 hr to fix
          menus/utils.py on lines 111..116

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

          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