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)
- 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
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 = []
- Read upRead up
- Exclude checks
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 = []
- 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
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)
- Read upRead up
- Exclude checks
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']))
- 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
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)
- Read upRead up
- Exclude checks
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 = []
- 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 order
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def order(pair_name, sell_or_buy, units, type = :market, options = {})
Line is too long. [94/80] Open
trade_reduced = convert_response_to_reduced_position(tx['tradeReduced'], tx['time'])
- Exclude checks
Line is too long. [87/80] Open
pair_name = Converter.convert_instrument_to_pair_name(trade_opened['instrument'])
- Exclude checks
Line is too long. [89/80] Open
detail['units'].to_i.abs, BigDecimal(detail['price'], 10), Time.parse(time), nil)
- Exclude checks
Line is too long. [82/80] Open
PricingUtils.detect_sell_or_buy(res['units']), t, Time.parse(res['time']))
- Exclude checks
Avoid the use of the case equality operator ===
. Open
units: sell_or_buy === :buy ? units : units * -1
- Read upRead up
- Exclude checks
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)
- Exclude checks
Useless assignment to variable - response
. Open
response = @client.account(@account['id'])
- Read upRead up
- Exclude checks
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|
- Read upRead up
- Exclude checks
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
- Exclude checks
Avoid the use of the case equality operator ===
. Open
options[:units] = order.sell_or_buy === :buy ? options[:units] : options[:units] * -1
- Read upRead up
- Exclude checks
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']))
- Exclude checks
Line is too long. [91/80] Open
options[:units] = order.sell_or_buy === :buy ? options[:units] : options[:units] * -1
- Exclude checks
Line is too long. [89/80] Open
detail['units'].to_i.abs, BigDecimal(detail['price'], 10), Time.parse(time), nil)
- Exclude checks
Line is too long. [120/80] Open
@order_validator.validate(order.pair_name, order.sell_or_buy, options[:units] || order.units, order.type, options)
- Exclude checks
Line is too long. [119/80] Open
order_opened = res['orderFillTransaction'] ? nil : convert_response_to_order(res['orderCreateTransaction'], type)
- Exclude checks