unageanu/jiji2

View on GitHub
src/jiji/model/trading/order.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Class has too many lines. [138/100]
Open

  class Order

    include Jiji::Errors
    include Jiji::Utils::ValueObject
    include Jiji::Web::Transport::Transportable
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for from_h is too high. [21.61/15]
Open

    def from_h(hash)
      hash.each do |k, v|
        k = k.to_sym
        unless v.nil?
          if k == :price || k == :price_bound || k == :initial_price
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

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 collect_properties has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def collect_properties(keys = instance_variables.map { |n| n[1..-1].to_sym })
      keys.each_with_object({}) do |name, obj|
        next if name == :broker

        v = instance_variable_get("@#{name}")
Severity: Minor
Found in src/jiji/model/trading/order.rb - About 2 hrs 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

Cyclomatic complexity for collect_properties is too high. [10/6]
Open

    def collect_properties(keys = instance_variables.map { |n| n[1..-1].to_sym })
      keys.each_with_object({}) do |name, obj|
        next if name == :broker

        v = instance_variable_get("@#{name}")
Severity: Minor
Found in src/jiji/model/trading/order.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.

Cyclomatic complexity for from_h is too high. [10/6]
Open

    def from_h(hash)
      hash.each do |k, v|
        k = k.to_sym
        unless v.nil?
          if k == :price || k == :price_bound || k == :initial_price
Severity: Minor
Found in src/jiji/model/trading/order.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 has too many lines. [14/10]
Open

    def from_h(hash)
      hash.each do |k, v|
        k = k.to_sym
        unless v.nil?
          if k == :price || k == :price_bound || k == :initial_price
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [14/10]
Open

    def collect_properties(keys = instance_variables.map { |n| n[1..-1].to_sym })
      keys.each_with_object({}) do |name, obj|
        next if name == :broker

        v = instance_variable_get("@#{name}")
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method from_h has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def from_h(hash)
      hash.each do |k, v|
        k = k.to_sym
        unless v.nil?
          if k == :price || k == :price_bound || k == :initial_price
Severity: Minor
Found in src/jiji/model/trading/order.rb - About 2 hrs 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

Perceived complexity for from_h is too high. [10/7]
Open

    def from_h(hash)
      hash.each do |k, v|
        k = k.to_sym
        unless v.nil?
          if k == :price || k == :price_bound || k == :initial_price
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Assignment Branch Condition size for collect_properties is too high. [18.19/15]
Open

    def collect_properties(keys = instance_variables.map { |n| n[1..-1].to_sym })
      keys.each_with_object({}) do |name, obj|
        next if name == :broker

        v = instance_variable_get("@#{name}")
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

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

Perceived complexity for collect_properties is too high. [10/7]
Open

    def collect_properties(keys = instance_variables.map { |n| n[1..-1].to_sym })
      keys.each_with_object({}) do |name, obj|
        next if name == :broker

        v = instance_variable_get("@#{name}")
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Assignment Branch Condition size for initialize is too high. [17/15]
Open

    def initialize(pair_name, internal_id,
      sell_or_buy, type, last_modified) #:nodoc:
      @pair_name     = pair_name
      @internal_id   = internal_id
      @sell_or_buy   = sell_or_buy
Severity: Minor
Found in src/jiji/model/trading/order.rb by rubocop

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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def initialize(pair_name, internal_id,
      sell_or_buy, type, last_modified) #:nodoc:
Severity: Minor
Found in src/jiji/model/trading/order.rb - About 35 mins to fix

    Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def initialize(internal_id, units,
          price, timestamp, profit_or_loss) #:nodoc:
    Severity: Minor
    Found in src/jiji/model/trading/order.rb - About 35 mins to fix

      Method carried_out? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def carried_out?(tick) #:nodoc:
            current = Utils::PricingUtils
              .calculate_entry_price(tick, pair_name, sell_or_buy)
            case @type
            when :market     then true
      Severity: Minor
      Found in src/jiji/model/trading/order.rb - About 35 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 collect_properties_for_modify has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def collect_properties_for_modify
            instance_variables.map { |n| n[1..-1].to_sym }.each_with_object({}) do |name, obj|
              next if name == :broker
      
              v = instance_variable_get("@#{name}")
      Severity: Minor
      Found in src/jiji/model/trading/order.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

      Line is too long. [110/80]
      Open

                if name == :take_profit_on_fill || name == :stop_loss_on_fill || name == :trailing_stop_loss_on_fill
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      Line is too long. [88/80]
      Open

            instance_variables.map { |n| n[1..-1].to_sym }.each_with_object({}) do |name, obj|
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
      Open

                if name == :price || name == :price_bound || name == :initial_price
                  v = v.to_s
                end
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

      Example:

      # bad
      a = 'a'
      foo if a == 'a' || a == 'b' || a == 'c'
      
      # good
      a = 'a'
      foo if ['a', 'b', 'c'].include?(a)

      Line is too long. [101/80]
      Open

                if k == :take_profit_on_fill || k == :stop_loss_on_fill || k == :trailing_stop_loss_on_fill
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      Line is too long. [81/80]
      Open

          def collect_properties(keys = instance_variables.map { |n| n[1..-1].to_sym })
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
      Open

                if k == :take_profit_on_fill || k == :stop_loss_on_fill || k == :trailing_stop_loss_on_fill
                  v = v.clone.symbolize_keys
                  v[:price] = BigDecimal(v[:price], 10) if v[:price]
                end
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

      Example:

      # bad
      a = 'a'
      foo if a == 'a' || a == 'b' || a == 'c'
      
      # good
      a = 'a'
      foo if ['a', 'b', 'c'].include?(a)

      Line is too long. [103/80]
      Open

        # ※各フィールドについて、詳しくは <a href="http://developer.oanda.com/rest-live-v20/order-df/">公式リファレンス</a> を参照ください。
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      Line is too long. [83/80]
      Open

            @take_profit_on_fill = @stop_loss_on_fill = @trailing_stop_loss_on_fill = nil
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
      Open

                if k == :price || k == :price_bound || k == :initial_price
                  v = BigDecimal(v, 10)
                end
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

      Example:

      # bad
      a = 'a'
      foo if a == 'a' || a == 'b' || a == 'c'
      
      # good
      a = 'a'
      foo if ['a', 'b', 'c'].include?(a)

      Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
      Open

                if name == :take_profit_on_fill || name == :stop_loss_on_fill || name == :trailing_stop_loss_on_fill
                  v = v.clone
                  v[:price] = v[:price].to_s if v[:price]
                end
      Severity: Minor
      Found in src/jiji/model/trading/order.rb by rubocop

      This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

      Example:

      # bad
      a = 'a'
      foo if a == 'a' || a == 'b' || a == 'c'
      
      # good
      a = 'a'
      foo if ['a', 'b', 'c'].include?(a)

      There are no issues that match your filters.

      Category
      Status