django/django

View on GitHub
django/contrib/auth/management/commands/createsuperuser.py

Summary

Maintainability
D
2 days
Test Coverage

Function handle has a Cognitive Complexity of 93 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(self, *args, **options):
        username = options[self.UserModel.USERNAME_FIELD]
        database = options["database"]
        user_data = {}
        verbose_field_name = self.username_field.verbose_name
Severity: Minor
Found in django/contrib/auth/management/commands/createsuperuser.py - About 1 day 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 createsuperuser.py has 282 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Management utility to create superusers.
"""

import getpass
Severity: Minor
Found in django/contrib/auth/management/commands/createsuperuser.py - About 2 hrs to fix

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

        def add_arguments(self, parser):
            parser.add_argument(
                "--%s" % self.UserModel.USERNAME_FIELD,
                help="Specifies the login for the superuser.",
            )
    Severity: Minor
    Found in django/contrib/auth/management/commands/createsuperuser.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

    Avoid deeply nested control flow statements.
    Open

                                if not input_value.strip():
                                    user_data[field_name] = None
                                    self.stderr.write("Error: This field cannot be blank.")
                                    continue
                                user_data[field_name] = [
    Severity: Major
    Found in django/contrib/auth/management/commands/createsuperuser.py - About 45 mins to fix

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

          def _validate_username(self, username, verbose_field_name, database):
              """Validate username. If invalid, return a string error message."""
              if self.username_is_unique:
                  try:
                      self.UserModel._default_manager.db_manager(database).get_by_natural_key(
      Severity: Minor
      Found in django/contrib/auth/management/commands/createsuperuser.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

      There are no issues that match your filters.

      Category
      Status