localstack/localstack

View on GitHub
localstack/aws/mocking.py

Summary

Maintainability
D
1 day
Test Coverage

File mocking.py has 332 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
import math
import random
import re
from datetime import date, datetime
Severity: Minor
Found in localstack/aws/mocking.py - About 4 hrs to fix

    Function generate_arn has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def generate_arn(shape: StringShape):
        if not shape.metadata:
            return DEFAULT_ARN
    
        def _generate_arn():
    Severity: Minor
    Found in localstack/aws/mocking.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 _ has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def _(shape: StringShape, graph: ShapeGraph) -> str:
        if shape.enum:
            return shape.enum[0]
    
        if shape.name in custom_strings:
    Severity: Minor
    Found in localstack/aws/mocking.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 sanitize_arn_pattern has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def sanitize_arn_pattern(pattern: str) -> str:
        # clown emoji
    
        # some devs were just lazy ...
        if pattern in [
    Severity: Minor
    Found in localstack/aws/mocking.py - About 1 hr to fix

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

      def populate_graph(graph: networkx.DiGraph, root: Shape):
          stack: List[Shape] = [root]
          visited: Set[str] = set()
      
          while stack:
      Severity: Minor
      Found in localstack/aws/mocking.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 shape_graph has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def shape_graph(root: Shape) -> ShapeGraph:
          graph = networkx.DiGraph()
          graph.root = root
          populate_graph(graph, root)
      
      
      Severity: Minor
      Found in localstack/aws/mocking.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

      Avoid too many return statements within this function.
      Open

                  return random.choice(words)
      Severity: Major
      Found in localstack/aws/mocking.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return val[: min(max_len, len(val))]
        Severity: Major
        Found in localstack/aws/mocking.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return "0" * str_len
          Severity: Major
          Found in localstack/aws/mocking.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return "a" * str_len
            Severity: Major
            Found in localstack/aws/mocking.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return datetime.now()
              Severity: Major
              Found in localstack/aws/mocking.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return random_string
                Severity: Major
                Found in localstack/aws/mocking.py - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status