bogdanRada/celluloid_pubsub

View on GitHub
lib/celluloid_pubsub/reactor.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Class Reactor has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Reactor
    include CelluloidPubsub::BaseActor

    # available actions that can be delegated
    AVAILABLE_ACTIONS = %w(unsubscribe_clients unsubscribe subscribe publish unsubscribe_all).freeze
Severity: Minor
Found in lib/celluloid_pubsub/reactor.rb - About 2 hrs to fix

    Method handle_parsed_websocket_message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_parsed_websocket_message(json_data)
          data =  json_data.is_a?(Hash) ? json_data.stringify_keys : {}
          if CelluloidPubsub::Reactor::AVAILABLE_ACTIONS.include?(data['client_action'].to_s)
            log_debug "#{self.class} finds actions for  #{json_data}"
            delegate_action(data) if data['client_action'].present?
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb - 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 run has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def run
          loop do
            break if Actor.current.dead? || @websocket.closed? || @server.dead?
            message = try_read_websocket
            handle_websocket_message(message) if message.present?
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb - 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

    Unnecessary spacing detected.
    Open

          data =  json_data.is_a?(Hash) ? json_data.stringify_keys : {}
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb by rubocop

    This cop checks for extra/unnecessary whitespace.

    Example:

    # good if AllowForAlignment is true
    name      = "RuboCop"
    # Some comment and an empty line
    
    website  += "/bbatsov/rubocop" unless cond
    puts        "rubocop"          if     debug
    
    # bad for any configuration
    set_app("RuboCop")
    website  = "https://github.com/bbatsov/rubocop"

    Avoid rescuing without specifying an error class.
    Open

        rescue => exception
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb by rubocop

    This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

    Example: EnforcedStyle: implicit

    # `implicit` will enforce using `rescue` instead of
    # `rescue StandardError`.
    
    # bad
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    Example: EnforcedStyle: explicit (default)

    # `explicit` will enforce using `rescue StandardError`
    # instead of `rescue`.
    
    # bad
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    Add an empty line after magic comments.
    Open

    require_relative './registry'
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb by rubocop

    Checks for a newline after the final magic comment.

    Example:

    # good
    # frozen_string_literal: true
    
    # Some documentation for Person
    class Person
      # Some code
    end
    
    # bad
    # frozen_string_literal: true
    # Some documentation for Person
    class Person
      # Some code
    end

    Avoid rescuing without specifying an error class.
    Open

        rescue => exception
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb by rubocop

    This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

    Example: EnforcedStyle: implicit

    # `implicit` will enforce using `rescue` instead of
    # `rescue StandardError`.
    
    # bad
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    Example: EnforcedStyle: explicit (default)

    # `explicit` will enforce using `rescue StandardError`
    # instead of `rescue`.
    
    # bad
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    Operator = should be surrounded by a single space.
    Open

          data =  json_data.is_a?(Hash) ? json_data.stringify_keys : {}
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Avoid rescuing without specifying an error class.
    Open

        rescue
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb by rubocop

    This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

    Example: EnforcedStyle: implicit

    # `implicit` will enforce using `rescue` instead of
    # `rescue StandardError`.
    
    # bad
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    Example: EnforcedStyle: explicit (default)

    # `explicit` will enforce using `rescue StandardError`
    # instead of `rescue`.
    
    # bad
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    %w-literals should be delimited by [ and ].
    Open

        AVAILABLE_ACTIONS = %w(unsubscribe_clients unsubscribe subscribe publish unsubscribe_all).freeze
    Severity: Minor
    Found in lib/celluloid_pubsub/reactor.rb by rubocop

    This cop enforces the consistent usage of %-literal delimiters.

    Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

    Example:

    # Style/PercentLiteralDelimiters:
    #   PreferredDelimiters:
    #     default: '[]'
    #     '%i':    '()'
    
    # good
    %w[alpha beta] + %i(gamma delta)
    
    # bad
    %W(alpha #{beta})
    
    # bad
    %I(alpha beta)

    There are no issues that match your filters.

    Category
    Status