wooyek/django-powerbank

View on GitHub

Showing 13 of 27 total issues

Function to_dict has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def to_dict(self, include=None, exclude=None):
        """
        Return a dict containing the entity's property values.

        :param include: Optional set of property names to include, default all.
Severity: Minor
Found in src/django_powerbank/db/models/base.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 optgroups has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def optgroups(self, name, value, attrs=None):
        """Return a list of optgroups for this widget."""
        default = (None, [], 0)
        groups = [default]
        # We must add at least one 'selected' option or widget will show nothing.
Severity: Minor
Found in src/django_powerbank/forms/widgets.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

Consider simplifying this complex logical expression.
Open

        if (query.high_mark is None and
                query.low_mark == 0 and
                not query.where and
                not query.select and
                not query.group_by and
Severity: Major
Found in src/django_powerbank/db/models/query.py - About 1 hr to fix

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

        def __init__(self, attrs=None, url=None, allow_create=False, value_field='text', label_field='text', search_field='text', plugins=[],
    Severity: Major
    Found in src/django_powerbank/forms/widgets.py - About 1 hr to fix

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

      def model_to_request_data_dict(model):
          """
          Removes fields with None value. Test client will serialize them into 'None' strings that will cause validation errors.
          """
          from django.forms import model_to_dict
      Severity: Minor
      Found in src/django_powerbank/testing/utils.py - 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 to_python has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_python(self, value):
              """
              Convert the input JSON value into python structures, raises
              django.core.exceptions.ValidationError if the data can't be converted.
              """
      Severity: Minor
      Found in src/django_powerbank/db/models/fields/__init__.py - 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 get_slug_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_slug_value(self, model_instance):
              value = super(UniqueSlugField, self).get_slug_value(model_instance)
              filters = {
                  self.attname + '__gte': value,
                  self.attname + '__lte': value + '-9999'
      Severity: Minor
      Found in src/django_powerbank/db/models/fields/__init__.py - 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

      Consider simplifying this complex logical expression.
      Open

              if (request.method != "GET" or
                      request.is_ajax() or
                      self.return_url or
                      referrer is None or
                      self.return_url is None and 'return_url' in request.GET):
      Severity: Major
      Found in src/django_powerbank/views/mixins.py - About 40 mins to fix

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

            def __init__(self, source_field=None, keep_existing=False, source_fallback=False, *args, **kwargs):
        Severity: Minor
        Found in src/django_powerbank/db/models/fields/__init__.py - About 35 mins to fix

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

              def assertNoFormErrors(self, response, form_context_key='form'):
                  if not hasattr(response, 'context_data'):
                      return
                  forms = response.context_data.get(form_context_key)
                  if forms is None:
          Severity: Minor
          Found in src/django_powerbank/testing/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

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

              def dispatch(self, request, *args, **kwargs):
                  """
                  Does request processing for return_url query parameter and redirects with it's missing
          
                  We can't do that in the get method, as it does not exist in the View base class
          Severity: Minor
          Found in src/django_powerbank/views/mixins.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

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

              def pre_save(self, model_instance, add):
                  if getattr(model_instance, self.attname) and self.keep_existing or not self.get_source_value(model_instance):
                      return super(AutoSlugField, self).pre_save(model_instance, add)
          
                  value = self.get_slug_value(model_instance)
          Severity: Minor
          Found in src/django_powerbank/db/models/fields/__init__.py - 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 count has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def count(self):
                  if self._result_cache is not None:
                      if hasattr(self, '_iter') and not self._iter:
                          return len(self._result_cache)
          
          
          Severity: Minor
          Found in src/django_powerbank/db/models/query.py - 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

          Severity
          Category
          Status
          Source
          Language