jalyna/oakdex-battle

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

Summary

Maintainability
A
1 hr
Test Coverage

Assignment Branch Condition size for valid_item_actions_for is too high. [22.2/20]
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 }

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

      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 }
Severity: Minor
Found in lib/oakdex/battle/valid_action_service.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

Use snake_case for variable names.
Open

      def possible_item_actions(battle_pokemon, item_id, prevActions = [])

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

        return [] if actions.select { |a| a.trainer == trainer }.size >= pokemon_per_trainer

There are no issues that match your filters.

Category
Status