divio/django-cms

View on GitHub
cms/plugin_base.py

Summary

Maintainability
D
1 day
Test Coverage

File plugin_base.py has 388 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import re

from django import forms
from django.contrib import admin, messages
Severity: Minor
Found in cms/plugin_base.py - About 5 hrs to fix

    CMSPluginBase has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CMSPluginBase(admin.ModelAdmin, metaclass=CMSPluginBaseMetaclass):
    
        name = ""
        module = _("Generic")  # To be overridden in child classes
    
    
    Severity: Minor
    Found in cms/plugin_base.py - About 3 hrs to fix

      Function __new__ has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def __new__(cls, name, bases, attrs):
              super_new = super(CMSPluginBaseMetaclass, cls).__new__
              parents = [base for base in bases if isinstance(base, CMSPluginBaseMetaclass)]
              if not parents:
                  # If this is CMSPluginBase itself, and not a subclass, don't do anything
      Severity: Minor
      Found in cms/plugin_base.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 render_change_form has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
      Severity: Minor
      Found in cms/plugin_base.py - About 45 mins to fix

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

            def __init__(self, name, url, data=None, question=None, action='ajax', attributes=None):
        Severity: Minor
        Found in cms/plugin_base.py - About 45 mins to fix

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

              def save_model(self, request, obj, form, change):
                  """
                  Override original method, and add some attributes to obj
                  This have to be made, because if object is newly created, he must know
                  where he lives.
          Severity: Minor
          Found in cms/plugin_base.py - 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

          There are no issues that match your filters.

          Category
          Status