unageanu/jiji2

View on GitHub
src/jiji/model/securities/internal/oanda/ordering.rb

Summary

Maintainability
A
1 hr
Test Coverage

Assignment Branch Condition size for modify_order is too high. [28.44/15]
Open

    def modify_order(internal_id, options = {})
      order = retrieve_order_by_id(internal_id)
      options = Converter.convert_option_to_oanda(options)
      options[:type] = Converter.convert_order_type_to_oanda(order.type)
      options[:instrument] = Converter.convert_pair_name_to_instrument(order.pair_name)

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 has too many lines. [20/10]
Open

    def convert_response_to_order_result(res, type)
      order_opened = res['orderFillTransaction'] ? nil : convert_response_to_order(res['orderCreateTransaction'], type)
      trade_opened = nil
      trade_reduced = nil
      trades_closed = []

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.

Assignment Branch Condition size for convert_response_to_order_result is too high. [23.02/15]
Open

    def convert_response_to_order_result(res, type)
      order_opened = res['orderFillTransaction'] ? nil : convert_response_to_order(res['orderCreateTransaction'], type)
      trade_opened = nil
      trade_reduced = nil
      trades_closed = []

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 has too many lines. [12/10]
Open

    def retrieve_orders(count = 500, pair_name = nil, max_id = nil)
      param = { count: count }
      if pair_name
        param[:instrument] =
          Converter.convert_pair_name_to_instrument(pair_name)

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.

Assignment Branch Condition size for convert_trade_opened_to_position is too high. [17.29/15]
Open

    def convert_trade_opened_to_position(trade_opened, type = nil)
      pair_name = Converter.convert_instrument_to_pair_name(trade_opened['instrument'])
      t = type || Converter.convert_order_type_from_oanda(res['type'])
      order = Order.new(pair_name, res['id'].to_s,
        PricingUtils.detect_sell_or_buy(res['units']), t, Time.parse(res['time']))

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 has too many lines. [11/10]
Open

    def modify_order(internal_id, options = {})
      order = retrieve_order_by_id(internal_id)
      options = Converter.convert_option_to_oanda(options)
      options[:type] = Converter.convert_order_type_to_oanda(order.type)
      options[:instrument] = Converter.convert_pair_name_to_instrument(order.pair_name)

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

    def convert_response_to_order_result(res, type)
      order_opened = res['orderFillTransaction'] ? nil : convert_response_to_order(res['orderCreateTransaction'], type)
      trade_opened = nil
      trade_reduced = nil
      trades_closed = []
Severity: Minor
Found in src/jiji/model/securities/internal/oanda/ordering.rb - About 55 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 order has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def order(pair_name, sell_or_buy, units, type = :market, options = {})
Severity: Minor
Found in src/jiji/model/securities/internal/oanda/ordering.rb - About 35 mins to fix

    Line is too long. [94/80]
    Open

              trade_reduced = convert_response_to_reduced_position(tx['tradeReduced'], tx['time'])

    Line is too long. [87/80]
    Open

          pair_name = Converter.convert_instrument_to_pair_name(trade_opened['instrument'])

    Line is too long. [89/80]
    Open

            detail['units'].to_i.abs, BigDecimal(detail['price'], 10), Time.parse(time), nil)

    Line is too long. [82/80]
    Open

            PricingUtils.detect_sell_or_buy(res['units']), t, Time.parse(res['time']))

    Avoid the use of the case equality operator ===.
    Open

              units:      sell_or_buy === :buy ? units : units * -1

    This cop checks for uses of the case equality operator(===).

    Example:

    # bad
    Array === something
    (1..100) === 7
    /something/ === some_string
    
    # good
    something.is_a?(Array)
    (1..100).include?(7)
    some_string =~ /something/

    Line is too long. [87/80]
    Open

          options[:instrument] = Converter.convert_pair_name_to_instrument(order.pair_name)

    Useless assignment to variable - response.
    Open

          response = @client.account(@account['id'])

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Avoid multi-line chains of blocks.
    Open

          end.map do |item|

    This cop checks for chaining of a block after another block that spans multiple lines.

    Example:

    Thread.list.find_all do |t|
      t.alive?
    end.map do |t|
      t.object_id
    end

    Line is too long. [104/80]
    Open

          pair_name = res['instrument'] ? Converter.convert_instrument_to_pair_name(res['instrument']) : nil

    Avoid the use of the case equality operator ===.
    Open

          options[:units] = order.sell_or_buy === :buy ? options[:units] : options[:units] * -1

    This cop checks for uses of the case equality operator(===).

    Example:

    # bad
    Array === something
    (1..100) === 7
    /something/ === some_string
    
    # good
    something.is_a?(Array)
    (1..100).include?(7)
    some_string =~ /something/

    Line is too long. [103/80]
    Open

            PricingUtils.detect_sell_or_buy(res['units']), t, Time.parse(res['time'] || res['createTime']))

    Line is too long. [91/80]
    Open

          options[:units] = order.sell_or_buy === :buy ? options[:units] : options[:units] * -1

    Line is too long. [89/80]
    Open

            detail['units'].to_i.abs, BigDecimal(detail['price'], 10), Time.parse(time), nil)

    Line is too long. [120/80]
    Open

          @order_validator.validate(order.pair_name, order.sell_or_buy, options[:units] || order.units, order.type, options)

    Line is too long. [119/80]
    Open

          order_opened = res['orderFillTransaction'] ? nil : convert_response_to_order(res['orderCreateTransaction'], type)

    There are no issues that match your filters.

    Category
    Status