motom001/DoorPi

View on GitHub
doorpi/action/handler.py

Summary

Maintainability
D
2 days
Test Coverage

Function fire_event_synchron has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    def fire_event_synchron(self, event_name, event_source, kwargs = None):
        silent = ONTIME in event_name
        if self.__destroy and not silent: return False

        event_fire_id = id_generator()
Severity: Minor
Found in doorpi/action/handler.py - About 3 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

File handler.py has 303 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
logger = logging.getLogger(__name__)
Severity: Minor
Found in doorpi/action/handler.py - About 3 hrs to fix

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

        def register_event(self, event_name, event_source):
            silent = ONTIME in event_name
            if not silent: logger.trace("register Event %s from %s ", event_name, event_source)
            self.register_source(event_source)
            if event_name not in self.__Events:
    Severity: Minor
    Found in doorpi/action/handler.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 unregister_source has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def unregister_source(self, event_source, force_unregister = False):
            try:
                logger.trace("unregister Eventsource %s and force_unregister is %s", event_source, force_unregister)
                if event_source not in self.__Sources: return "event_source %s unknown" % (event_source)
                for event_name in self.__Events.keys():
    Severity: Minor
    Found in doorpi/action/handler.py - About 45 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 insert_event_log has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def insert_event_log(self, event_id, fired_by, event_name, start_time, additional_infos):
    Severity: Minor
    Found in doorpi/action/handler.py - About 35 mins to fix

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

          def register_action(self, event_name, action_object, *args, **kwargs):
              if ismethod(action_object) and callable(action_object):
                  action_object = SingleAction(action_object, *args, **kwargs)
              elif isfunction(action_object) and callable(action_object):
                  action_object = SingleAction(action_object, *args, **kwargs)
      Severity: Minor
      Found in doorpi/action/handler.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 events_by_source has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def events_by_source(self):
              events_by_source = {}
              for event in self.events:
                  for source in self.events[event]:
                      if source in events_by_source:
      Severity: Minor
      Found in doorpi/action/handler.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 "no actions for this event"
      Severity: Major
      Found in doorpi/action/handler.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return True
        Severity: Major
        Found in doorpi/action/handler.py - About 30 mins to fix

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

                      if not os.path.exists(os.path.dirname(file_name)):
                          logger.info('Path %s does not exist - creating it now', os.path.dirname(file_name))
                          os.makedirs(os.path.dirname(file_name))
          Severity: Major
          Found in doorpi/action/handler.py and 1 other location - About 2 hrs to fix
          doorpi/conf/config_object.py on lines 86..88

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

          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

                  if 'last_duration' not in self.__additional_informations[event_name]:
                      self.__additional_informations[event_name]['last_duration'] = None
          Severity: Minor
          Found in doorpi/action/handler.py and 1 other location - About 55 mins to fix
          doorpi/action/handler.py on lines 274..275

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

          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

                  if 'last_finished' not in self.__additional_informations[event_name]:
                      self.__additional_informations[event_name]['last_finished'] = None
          Severity: Minor
          Found in doorpi/action/handler.py and 1 other location - About 55 mins to fix
          doorpi/action/handler.py on lines 277..278

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

          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

          There are no issues that match your filters.

          Category
          Status