lib/oakdex/battle/action.rb
Class Action
has 29 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Action
RECALL_PRIORITY = 7
ITEM_PRIORITY = 6
extend Forwardable
Assignment Branch Condition size for execute_use_item is too high. [30.68/20] Open
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
- Read upRead up
- Exclude checks
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
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
- Read upRead up
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
Open
while pokemon.growth_event? do
- Read upRead up
- Exclude checks
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