ettoreleandrotognoli/python-ami

View on GitHub
asterisk/ami/client.py

Summary

Maintainability
C
7 hrs
Test Coverage

AMIClient has 24 functions (exceeds 20 allowed). Consider refactoring.
Open

class AMIClient(object):
    asterisk_start_regex = re.compile(r'^Asterisk *Call *Manager/(?P<version>([0-9]+\.)*[0-9]+)', re.IGNORECASE)
    asterisk_line_regex = re.compile(b'\r\n', re.IGNORECASE | re.MULTILINE)
    asterisk_pack_regex = re.compile(b'\r\n\r\n', re.IGNORECASE | re.MULTILINE)

Severity: Minor
Found in asterisk/ami/client.py - About 2 hrs to fix

    File client.py has 274 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import re
    import socket
    import threading
    from functools import partial
    
    
    Severity: Minor
    Found in asterisk/ami/client.py - About 2 hrs to fix

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

          def _next_pack(self):
              data = b''
              while not self.finished.is_set():
                  recv = self._socket.recv(self._buffer_size)
                  if recv == b'':
      Severity: Minor
      Found in asterisk/ami/client.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 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, address='127.0.0.1', port=5038,
      Severity: Major
      Found in asterisk/ami/client.py - About 50 mins to fix

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

            def _login_wrapper(self, *args, **kwargs):
                callback = kwargs.pop('callback', None) or (lambda *a, **k: None)
        
                def on_login(response, *a, **k):
                    if not response.is_error():
        Severity: Minor
        Found in asterisk/ami/client.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