Xzanth/pugbot

View on GitHub
lib/pugbot/handlers.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Class BotPlugin has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

  class BotPlugin
    # Set up variables, called when the bot first connects to irc. Start an
    # array of names to not pmsg back.
    # @return [void]
    def initialize(*args)
Severity: Minor
Found in lib/pugbot/handlers.rb - About 3 hrs to fix

    Method finish has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def finish(m, arg1, arg2)
          user = m.user
          if arg1.nil?
            game = @queue_list.find_game_playing(m.user)
            return user.notice FINISH_NOT_INGAME if game.nil?
    Severity: Minor
    Found in lib/pugbot/handlers.rb - 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

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

        def remove(m, name, arg)
          queue = @queue_list.find_queue_by_arg(arg)
          user = User(name)
          return m.user.notice ACCESS_DENIED unless m.channel.opped?(m.user)
          return m.user.notice USERS_NOT_FOUND if user.nil?
    Severity: Minor
    Found in lib/pugbot/handlers.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 del has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def del(m, arg)
          queue = @queue_list.find_queue_by_arg(arg)
          user = m.user
          return user.notice YOU_ARE_PLAYING if playing?(user)
          return del_from_all(m, user) if arg.nil? || arg == "all"
    Severity: Minor
    Found in lib/pugbot/handlers.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 add has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def add(m, arg)
          queue = @queue_list.find_queue_by_arg(arg)
          user = m.user
          if /.+otenet.gr/ =~ user.host
            @xtremecount += 1
    Severity: Minor
    Found in lib/pugbot/handlers.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

    Use each_key instead of keys.each.
    Open

          @channel.users.keys.each do |u|
    Severity: Minor
    Found in lib/pugbot/handlers.rb by rubocop

    This cop checks for uses of each_key and each_value Hash methods.

    Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

    Example:

    # bad
    hash.keys.each { |k| p k }
    hash.values.each { |v| p v }
    hash.each { |k, _v| p k }
    hash.each { |_k, v| p v }
    
    # good
    hash.each_key { |k| p k }
    hash.each_value { |v| p v }

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

          unless queue.games.empty?
    Severity: Minor
    Found in lib/pugbot/handlers.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    There are no issues that match your filters.

    Category
    Status