jalyna/oakdex-battle

View on GitHub
lib/oakdex/battle/action.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Class Action has 29 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Action
      RECALL_PRIORITY = 7
      ITEM_PRIORITY = 6

      extend Forwardable
Severity: Minor
Found in lib/oakdex/battle/action.rb - About 3 hrs to fix

    Assignment Branch Condition size for execute_use_item is too high. [30.68/20]
    Open

          def execute_use_item
            add_log 'uses_item_on_pokemon', trainer.name, pokemon.name, item_id
            consumed = pokemon.use_item(item_id, in_battle: true)
            trainer.consume_item(item_id) if consumed
            action_id = 0
    Severity: Minor
    Found in lib/oakdex/battle/action.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

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

          def execute_use_item
            add_log 'uses_item_on_pokemon', trainer.name, pokemon.name, item_id
            consumed = pokemon.use_item(item_id, in_battle: true)
            trainer.consume_item(item_id) if consumed
            action_id = 0
    Severity: Minor
    Found in lib/oakdex/battle/action.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

    Do not use do with multi-line while.
    Open

            while pokemon.growth_event? do
    Severity: Minor
    Found in lib/oakdex/battle/action.rb by rubocop

    Checks for uses of do in multi-line while/until statements.

    Example:

    # bad
    while x.any? do
      do_something(x.pop)
    end
    
    # good
    while x.any?
      do_something(x.pop)
    end

    Example:

    # bad
    until x.empty? do
      do_something(x.pop)
    end
    
    # good
    until x.empty?
      do_something(x.pop)
    end

    There are no issues that match your filters.

    Category
    Status