motom001/DoorPi

View on GitHub
doorpi/keyboard/from_gpio.py

Summary

Maintainability
C
7 hrs
Test Coverage

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

    def __init__(self, input_pins, output_pins, conf_pre, conf_post, keyboard_name,
                 bouncetime=200, polarity=0, pressed_on_key_down=True, *args, **kwargs):
        logger.debug("__init__(input_pins = %s, output_pins = %s, bouncetime = %s, polarity = %s)",
                     input_pins, output_pins, bouncetime, polarity)
        self.keyboard_name = keyboard_name
Severity: Minor
Found in doorpi/keyboard/from_gpio.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, input_pins, output_pins, conf_pre, conf_post, keyboard_name,
Severity: Major
Found in doorpi/keyboard/from_gpio.py - About 1 hr to fix

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

        def event_detect(self, pin):
            if self.status_input(pin):
                self._fire_OnKeyDown(pin, __name__)
                if self._pressed_on_key_down:  # issue 134
                    self._fire_OnKeyPressed(pin, __name__)
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.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

    Method "__init__" has 11 parameters, which is greater than the 7 authorized.
    Open

        def __init__(self, input_pins, output_pins, conf_pre, conf_post, keyboard_name,
                     bouncetime=200, polarity=0, pressed_on_key_down=True, *args, **kwargs):
    Severity: Major
    Found in doorpi/keyboard/from_gpio.py by sonar-python

    A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

    Noncompliant Code Example

    With a maximum number of 4 parameters:

    def do_something(param1, param2, param3, param4, param5):
        ...
    

    Compliant Solution

    def do_something(param1, param2, param3, param4):
        ...
    

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

        def status_input(self, pin):
            if self._polarity is 0:
                return str(RPiGPIO.input(int(pin))).lower() in HIGH_LEVEL
            else:
                return str(RPiGPIO.input(int(pin))).lower() in LOW_LEVEL
    Severity: Major
    Found in doorpi/keyboard/from_gpio.py and 1 other location - About 4 hrs to fix
    doorpi/keyboard/from_piface.py on lines 71..75

    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 74.

    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

    Module level import not at top of file
    Open

    import RPi.GPIO as RPiGPIO # basic for GPIO control
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Place imports at the top of the file.

    Always put imports at the top of the file, just after any module
    comments and docstrings, and before module globals and constants.
    
    Okay: import os
    Okay: # this is a comment\nimport os
    Okay: '''this is a module docstring'''\nimport os
    Okay: r'''this is a module docstring'''\nimport os
    Okay:
    try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y
    Okay:
    try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y
    E402: a=1\nimport os
    E402: 'One string'\n"Two string"\nimport os
    E402: a=1\nfrom sys import x
    
    Okay: if x:\n    import os

    Line too long (99 > 79 characters)
    Open

            logger.debug("__init__(input_pins = %s, output_pins = %s, bouncetime = %s, polarity = %s)",
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (112 > 79 characters)
    Open

                logger.warning('you use an old version of GPIO library - fallback to single-register of input pins')
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (88 > 79 characters)
    Open

                     bouncetime=200, polarity=0, pressed_on_key_down=True, *args, **kwargs):
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (83 > 79 characters)
    Open

        def __init__(self, input_pins, output_pins, conf_pre, conf_post, keyboard_name,
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (88 > 79 characters)
    Open

            if doorpi.DoorPi().config.get(section_name, 'mode', "BOARD").upper() == "BOARD":
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (112 > 79 characters)
    Open

                logger.warning('you use an old version of GPIO library - fallback to single-register of input pins')
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    At least two spaces before inline comment
    Open

    import RPi.GPIO as RPiGPIO # basic for GPIO control
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Separate inline comments by at least two spaces.

    An inline comment is a comment on the same line as a statement.
    Inline comments should be separated by at least two spaces from the
    statement. They should start with a # and a single space.
    
    Each line of a block comment starts with a # and a single space
    (unless it is indented text inside the comment).
    
    Okay: x = x + 1  # Increment x
    Okay: x = x + 1    # Increment x
    Okay: # Block comment
    E261: x = x + 1 # Increment x
    E262: x = x + 1  #Increment x
    E262: x = x + 1  #  Increment x
    E265: #Block comment
    E266: ### Block comment

    Line too long (94 > 79 characters)
    Open

    from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (98 > 79 characters)
    Open

            pull_up_down = doorpi.DoorPi().config.get(section_name, 'pull_up_down', "PUD_OFF").upper()
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Module level import not at top of file
    Open

    import doorpi
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Place imports at the top of the file.

    Always put imports at the top of the file, just after any module
    comments and docstrings, and before module globals and constants.
    
    Okay: import os
    Okay: # this is a comment\nimport os
    Okay: '''this is a module docstring'''\nimport os
    Okay: r'''this is a module docstring'''\nimport os
    Okay:
    try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y
    Okay:
    try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y
    E402: a=1\nimport os
    E402: 'One string'\n"Two string"\nimport os
    E402: a=1\nfrom sys import x
    
    Okay: if x:\n    import os

    Module level import not at top of file
    Open

    from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Place imports at the top of the file.

    Always put imports at the top of the file, just after any module
    comments and docstrings, and before module globals and constants.
    
    Okay: import os
    Okay: # this is a comment\nimport os
    Okay: '''this is a module docstring'''\nimport os
    Okay: r'''this is a module docstring'''\nimport os
    Okay:
    try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y
    Okay:
    try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y
    E402: a=1\nimport os
    E402: 'One string'\n"Two string"\nimport os
    E402: a=1\nfrom sys import x
    
    Okay: if x:\n    import os

    Line too long (94 > 79 characters)
    Open

                logger.debug("out(pin = %s, value = %s, log_output = %s)", pin, value, log_output)
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    Line too long (81 > 79 characters)
    Open

                RPiGPIO.setup(self._InputPins, RPiGPIO.IN, pull_up_down=pull_up_down)
    Severity: Minor
    Found in doorpi/keyboard/from_gpio.py by pep8

    Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.
    
    Reports error E501.

    There are no issues that match your filters.

    Category
    Status