django/django

View on GitHub
django/contrib/gis/utils/layermapping.py

Summary

Maintainability
F
4 days
Test Coverage

Function save has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
Open

    def save(self, verbose=False, fid_range=False, step=False,
             progress=False, silent=False, stream=sys.stdout, strict=False):
        """
        Save the contents from the OGR DataSource Layer into the database
        according to the mapping dictionary given at initialization.
Severity: Minor
Found in django/contrib/gis/utils/layermapping.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

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

    def check_layer(self):
        """
        Check the Layer metadata and ensure that it's compatible with the
        mapping information and model. Unlike previous revisions, there is no
        need to increment through each feature in the Layer.
Severity: Minor
Found in django/contrib/gis/utils/layermapping.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 layermapping.py has 450 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# LayerMapping -- A Django Model/OGR Layer Mapping Utility
"""
 The LayerMapping class provides a way to map the contents of OGR
 vector files (e.g. SHP files) to Geographic-enabled Django models.

Severity: Minor
Found in django/contrib/gis/utils/layermapping.py - About 6 hrs to fix

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

        def verify_ogr_field(self, ogr_field, model_field):
            """
            Verify if the OGR Field contents are acceptable to the model field. If
            they are, return the verified value, otherwise raise an exception.
            """
    Severity: Minor
    Found in django/contrib/gis/utils/layermapping.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 __init__ has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, model, data, mapping, layer=0,
                     source_srs=None, encoding='utf-8',
                     transaction_mode='commit_on_success',
                     transform=True, unique=None, using=None):
            """
    Severity: Minor
    Found in django/contrib/gis/utils/layermapping.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 __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, model, data, mapping, layer=0,
    Severity: Major
    Found in django/contrib/gis/utils/layermapping.py - About 1 hr to fix

      Function check_unique has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def check_unique(self, unique):
              "Check the `unique` keyword parameter -- may be a sequence or string."
              if isinstance(unique, (list, tuple)):
                  # List of fields to determine uniqueness with
                  for attr in unique:
      Severity: Minor
      Found in django/contrib/gis/utils/layermapping.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 save has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def save(self, verbose=False, fid_range=False, step=False,
      Severity: Major
      Found in django/contrib/gis/utils/layermapping.py - About 50 mins to fix

        Function feature_kwargs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def feature_kwargs(self, feat):
                """
                Given an OGR Feature, return a dictionary of keyword arguments for
                constructing the mapped model.
                """
        Severity: Minor
        Found in django/contrib/gis/utils/layermapping.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

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

            def check_fid_range(self, fid_range):
                "Check the `fid_range` keyword."
                if fid_range:
                    if isinstance(fid_range, (tuple, list)):
                        return slice(*fid_range)
        Severity: Minor
        Found in django/contrib/gis/utils/layermapping.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 check_srs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def check_srs(self, source_srs):
                "Check the compatibility of the given spatial reference object."
        
                if isinstance(source_srs, SpatialReference):
                    sr = source_srs
        Severity: Minor
        Found in django/contrib/gis/utils/layermapping.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