Showing 15 of 15 total issues
Class Action
has 29 methods (exceeds 20 allowed). Consider refactoring. 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
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
Class ActiveInBattlePokemon
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class ActiveInBattlePokemon
extend Forwardable
def_delegators :@pokemon, :moves_with_pp, :fainted?, :id
def_delegators :@side, :battle
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 }
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
STAGE_MULTIPLIERS_ACC_EVA = {
-6 => Rational(3, 9),
-5 => Rational(3, 8),
-4 => Rational(3, 7),
-3 => Rational(3, 6),
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 54.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
STAGE_MULTIPLIERS = {
-6 => Rational(2, 8),
-5 => Rational(2, 7),
-4 => Rational(2, 6),
-3 => Rational(2, 5),
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 54.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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 }
- 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
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
- 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
Method execute_stat_modifiers
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def execute_stat_modifiers
return if move.stat_modifiers.empty?
move.stat_modifiers.each do |stat_modifier|
modifier_target = stat_modifier['affects_user'] ? pokemon : target
stat = stat_modifier['stat']
- 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
Method execute
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def execute
execute_status_conditions(:before_turn)
@actions.each { |a| a.turn = self }
ordered_actions.each do |action|
- 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
Method targets_in_battle
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def targets_in_battle(move)
available_targets(move).map do |targets|
if targets.last.is_a?(Array)
targets if targets_in_battle?(targets)
elsif target_in_battle?(targets)
- 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
Method compare_actions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def compare_actions(a, b)
a_prio = a.priority
b_prio = b.priority
if a_prio == b_prio && a_prio < 6
if a.pokemon.speed == b.pokemon.speed
- 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
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
Use snake_case for variable names. 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
return [] if actions.select { |a| a.trainer == trainer }.size >= pokemon_per_trainer
- Exclude checks