lib/oakdex/battle/valid_action_service.rb
Assignment Branch Condition size for valid_item_actions_for is too high. [22.2/20] Open
Open
def valid_item_actions_for(trainer)
return [] if actions.select { |a| a.trainer == trainer }.size >= pokemon_per_trainer
trainer.items.flat_map do |item_id|
trainer.team.flat_map.with_index do |pokemon, i|
next if actions.any? { |a| a.item_id == item_id }
- 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 valid_item_actions_for
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
def valid_item_actions_for(trainer)
return [] if actions.select { |a| a.trainer == trainer }.size >= pokemon_per_trainer
trainer.items.flat_map do |item_id|
trainer.team.flat_map.with_index do |pokemon, i|
next if actions.any? { |a| a.item_id == item_id }
- 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
Use snake_case for variable names. Open
Open
def possible_item_actions(battle_pokemon, item_id, prevActions = [])
- Read upRead up
- Exclude checks
This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.
Example: EnforcedStyle: snake_case (default)
# bad
fooBar = 1
# good
foo_bar = 1
Example: EnforcedStyle: camelCase
# bad
foo_bar = 1
# good
fooBar = 1
Line is too long. [92/80] Open
Open
return [] if actions.select { |a| a.trainer == trainer }.size >= pokemon_per_trainer
- Exclude checks