OpServ-Monitoring/opserv-backend

View on GitHub
app/server/restful_api/data/v1/endpoints/gatheringrates.py

Summary

Maintainability
A
3 hrs
Test Coverage

Function __get_all_component_metrics has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def __get_all_component_metrics(cls) -> dict:
        from misc.constants import implemented_hardware, component_needs_arg

        component_metrics = {}
        for component_type in implemented_hardware:
Severity: Minor
Found in app/server/restful_api/data/v1/endpoints/gatheringrates.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

Consider simplifying this complex logical expression.
Open

        if "component_type" not in request_body or request_body["component_type"] not in component_metrics_dict:
            # TODO Future version: Log and return error message

            return self.STOP_PROCESSING()
        elif "component_arg" not in request_body \
Severity: Major
Found in app/server/restful_api/data/v1/endpoints/gatheringrates.py - About 1 hr to fix

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

        def _put(self) -> bool:
            request_body = self._request_holder.get_body()
    
            component_metrics_dict = self.__get_all_component_metrics()
    
    
    Severity: Minor
    Found in app/server/restful_api/data/v1/endpoints/gatheringrates.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 self.KEEP_PROCESSING()
    Severity: Major
    Found in app/server/restful_api/data/v1/endpoints/gatheringrates.py - About 30 mins to fix

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

          def __parse_component_metrics_dict_to_list(cls, component_metric_dict: dict) -> list:
              component_metric_list = []
      
              for component_type in component_metric_dict:
                  for component_arg in component_metric_dict[component_type]:
      Severity: Minor
      Found in app/server/restful_api/data/v1/endpoints/gatheringrates.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