reedstonefood/machi_koro

View on GitHub
lib/machi_koro/databank.rb

Summary

Maintainability
A
1 hr
Test Coverage

Cyclomatic complexity for is_activated is too high. [8/6]
Open

    def is_activated(roll, owners_turn)
      return false if !(@attribute[:from_roll] <= roll && @attribute[:to_roll] >= roll)
      return true if @attribute[:colour] == :blue
      return true if @attribute[:colour] == :green && owners_turn
      return true if @attribute[:colour] == :red && !owners_turn
Severity: Minor
Found in lib/machi_koro/databank.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method initialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(data)
      @attribute = Hash.new()
      [:cost, :from_roll, :to_roll, :base_income].each do |attr|
        @attribute[attr] = data[attr.to_s].to_i
      end
Severity: Minor
Found in lib/machi_koro/databank.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

Method initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(data)
      @ability = Array.new()
      [:dole_money, :harbour, :two_dice, :reroll, :symbol_boost, :no_buy_boost, :double_free_turn].each do |attr|
        @ability << attr if data[attr.to_s].to_s=="1"
      end
Severity: Minor
Found in lib/machi_koro/databank.rb - About 25 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

Method is_activated has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def is_activated(roll, owners_turn)
      return false if !(@attribute[:from_roll] <= roll && @attribute[:to_roll] >= roll)
      return true if @attribute[:colour] == :blue
      return true if @attribute[:colour] == :green && owners_turn
      return true if @attribute[:colour] == :red && !owners_turn
Severity: Minor
Found in lib/machi_koro/databank.rb - About 25 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

Unused block argument - data. You can omit the argument if you don't care about it.
Open

      @db.send(method_that_loads).each do |data|
Severity: Minor
Found in lib/machi_koro/databank.rb by rubocop

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

The use of eval is a serious security risk.
Open

        var << eval("#{class_name}.new(data)")
Severity: Minor
Found in lib/machi_koro/databank.rb by rubocop

This cop checks for the use of Kernel#eval and Binding#eval.

Example:

# bad

eval(something)
binding.eval(something)

There are no issues that match your filters.

Category
Status