ettoreleandrotognoli/python-ami

View on GitHub

Showing 14 of 14 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        for rule in self.black_list:
            if isinstance(rule, basestring) and event_name == rule:
                return False
            if isinstance(rule, PatternType) and rule.match(event_name) is not None:
                return False
Severity: Major
Found in asterisk/ami/event.py and 1 other location - About 2 hrs to fix
asterisk/ami/event.py on lines 98..102

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        for rule in self.white_list:
            if isinstance(rule, basestring) and event_name == rule:
                return True
            if isinstance(rule, PatternType) and rule.search(event_name) is not None:
                return True
Severity: Major
Found in asterisk/ami/event.py and 1 other location - About 2 hrs to fix
asterisk/ami/event.py on lines 106..110

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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 read has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def read(response):
              lines = response.splitlines()
              (key, value) = map(lambda s: s.strip(), lines[0].split(':', 1))
              if not key.lower() == 'response':
                  raise Exception()
      Severity: Minor
      Found in asterisk/ami/response.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 _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 check_white_list has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def check_white_list(self, event_name):
                if self.white_list is None:
                    return True
                for rule in self.white_list:
                    if isinstance(rule, basestring) and event_name == rule:
        Severity: Minor
        Found in asterisk/ami/event.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

        Function __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, on_event=None, white_list=None, black_list=[], **kwargs):
                self.white_list = [white_list] if isinstance(white_list, (basestring, PatternType)) else white_list
                self.black_list = [black_list] if isinstance(black_list, (basestring, PatternType)) else black_list
                for k in list(kwargs.keys()):
                    if k.startswith('on_'):
        Severity: Minor
        Found in asterisk/ami/event.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

        Function read has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def read(event):
                lines = event.splitlines()
                (key, value) = lines[0].split(': ', 1)
                if not key.lower() == 'event':
                    raise Exception()
        Severity: Minor
        Found in asterisk/ami/event.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                for key in self.keys:
                    package += '%s: %s\r\n' % (key, self.keys[key])
        Severity: Minor
        Found in asterisk/ami/action.py and 1 other location - About 30 mins to fix
        asterisk/ami/action.py on lines 11..12

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 32.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                for var in self.variables:
                    package += 'Variable: %s=%s\r\n' % (var, self.variables[var])
        Severity: Minor
        Found in asterisk/ami/action.py and 1 other location - About 30 mins to fix
        asterisk/ami/action.py on lines 9..10

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 32.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

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

            def check_attribute(self, rules, value):
                if isinstance(rules, (PatternType, basestring)):
                    rules = [rules]
                for rule in rules:
                    if isinstance(rule, basestring) and rule == value:
        Severity: Minor
        Found in asterisk/ami/event.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 _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

        Severity
        Category
        Status
        Source
        Language