treyhunner/django-simple-history

View on GitHub

Showing 49 of 49 total issues

Function _bulk_history_create has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
Open

    def _bulk_history_create(self, model, batch_size):
        """Save a copy of all instances to the historical model.

        :param model: Model you want to bulk create
        :param batch_size: number of models to create at once.
Severity: Minor
Found in simple_history/management/commands/populate_history.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 handle has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
Open

    def handle(self, *args, **options):
        self.verbosity = options["verbosity"]

        to_process = set()
        model_strings = options.get("models", []) or args
Severity: Minor
Found in simple_history/management/commands/populate_history.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

Method "bulk_history_create" has 8 parameters, which is greater than the 7 authorized.
Open

        self,
        objs,
        batch_size=None,
        update=False,
        default_user=None,
Severity: Major
Found in simple_history/manager.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

Rename function "HistoryRequestMiddleware" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
Open

def HistoryRequestMiddleware(get_response):
Severity: Major
Found in simple_history/middleware.py by sonar-python

Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

Noncompliant Code Example

With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

def MyFunction(a,b):
    ...

Compliant Solution

def my_function(a,b):
    ...

Function "bulk_update_with_history" has 9 parameters, which is greater than the 7 authorized.
Open

    objs,
    model,
    fields,
    batch_size=None,
    default_user=None,
Severity: Major
Found in simple_history/utils.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert (
                self.min_begin_len
                + self.placeholder_len
                + self.min_common_len
                + (max_len - prefix_len)
Severity: Info
Found in simple_history/template_utils.py by bandit

Function "bulk_create_with_history" has 8 parameters, which is greater than the 7 authorized.
Open

    objs,
    model,
    batch_size=None,
    ignore_conflicts=False,
    default_user=None,
Severity: Major
Found in simple_history/utils.py by sonar-python

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

Noncompliant Code Example

With a maximum number of 4 parameters:

def do_something(param1, param2, param3, param4, param5):
    ...

Compliant Solution

def do_something(param1, param2, param3, param4):
    ...

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
Open

    def _process(self, to_process, date_back=None, dry_run=True):

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Merge this if statement with the enclosing one.
Open

            if self.verbosity >= 1:

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if condition1:
    if condition2:
        # ...

Compliant Solution

if condition1 and condition2:
    # ...
Severity
Category
Status
Source
Language