FarmBot/Farmbot-Web-App

View on GitHub
app/controllers/api/rmq_utils_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

Method if_topic_is_safe has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def if_topic_is_safe
      if farmbot_demo?
        a, b, c = (routing_key_param || "").split(".")

        if !(permission_param == "read")
Severity: Minor
Found in app/controllers/api/rmq_utils_controller.rb - About 2 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

Class RmqUtilsController has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

  class RmqUtilsController < Api::AbstractController
    class BrokerConnectionLimiter
      attr_reader :cache

      CACHE_KEY_TPL = "mqtt_limiter:%s"
Severity: Minor
Found in app/controllers/api/rmq_utils_controller.rb - About 2 hrs to fix

    Method if_topic_is_safe has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def if_topic_is_safe
          if farmbot_demo?
            a, b, c = (routing_key_param || "").split(".")
    
            if !(permission_param == "read")
    Severity: Minor
    Found in app/controllers/api/rmq_utils_controller.rb - About 1 hr to fix

      Method maybe_continue has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def maybe_continue(username)
              is_guest = (username == FARMBOT_DEMO_USER)
              max = is_guest ? MAX_GUEST_COUNT : PER_DEVICE_MAX
              key = CACHE_KEY_TPL % username
              total = (cache.get(key) || "0").to_i
      Severity: Minor
      Found in app/controllers/api/rmq_utils_controller.rb - About 55 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 topic_action has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def topic_action # Called during subscribe
            # Example JSON:
            #   "name"        => "amq.topic",
            #   "permission"  => "read",
            #   "resource"    => "topic",
      Severity: Minor
      Found in app/controllers/api/rmq_utils_controller.rb - 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

      Avoid too many return statements within this method.
      Open

                return
      Severity: Major
      Found in app/controllers/api/rmq_utils_controller.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                  return
        Severity: Major
        Found in app/controllers/api/rmq_utils_controller.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return
          Severity: Major
          Found in app/controllers/api/rmq_utils_controller.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return
            Severity: Major
            Found in app/controllers/api/rmq_utils_controller.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                        return
              Severity: Major
              Found in app/controllers/api/rmq_utils_controller.rb - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status