digidotcom/python-suitcase

View on GitHub
suitcase/protocol.py

Summary

Maintainability
B
6 hrs
Test Coverage

Function _create_packet_generator has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    def _create_packet_generator(self):
        while True:
            curmsg = self.message_schema()
            for i, (_name, field) in enumerate(curmsg):
                bytes_required = field.bytes_required
Severity: Minor
Found in suitcase/protocol.py - About 4 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

Avoid deeply nested control flow statements.
Open

                        if len(self._available_bytes) < bytes_required:
                            yield None
                            continue

Severity: Major
Found in suitcase/protocol.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if idx == -1:  # no match in buffer
                                # Since we know the entire magic_seq is not here, there can be at most
                                # bytes_required - 1 bytes of the magic_seq available.  Thus we keep
                                # that many bytes around in case it is the start of the magic field.
                                self._available_bytes = self._available_bytes[-(bytes_required - 1):]
    Severity: Major
    Found in suitcase/protocol.py - About 45 mins to fix

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

          def feed(self, new_bytes):
              """Feed a new set of bytes into the protocol handler
      
              These bytes will be immediately fed into the parsing state machine and
              if new packets are found, the ``packet_callback`` will be executed
      Severity: Minor
      Found in suitcase/protocol.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