unageanu/jiji2

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

Summary

Maintainability
B
4 hrs
Test Coverage

Class ClosingPolicy has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

  class ClosingPolicy

    include Mongoid::Document
    include Jiji::Errors
    include Jiji::Utils::ValueObject
Severity: Minor
Found in src/jiji/model/trading/closing_policy.rb - About 2 hrs to fix

    Method update_from_order_options has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def update_from_order_options(options, price) #:nodoc:
          if options.include?(:stopLoss)
            self.stop_loss = !options[:stopLoss].nil? ? \
              ClosingPolicy.extract_stop_loss_from_order(options[:stopLoss], price) : 0
          end
    Severity: Minor
    Found in src/jiji/model/trading/closing_policy.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 calculate_trailing_amount has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def calculate_trailing_amount(position, price, amount)
          if position.sell_or_buy == :buy
            new_price = (price - amount).to_f
            trailing_amount&.zero? ?
              new_price : [new_price, trailing_amount].max
    Severity: Minor
    Found in src/jiji/model/trading/closing_policy.rb - About 45 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

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

          return false if take_profit&.zero?

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

          return if trailing_stop&.zero?

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

            trailing_amount&.zero? ?

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

          return false if stop_loss&.zero?

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

          return false if trailing_amount&.zero?

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

            trailing_amount&.zero? ?

    There are no issues that match your filters.

    Category
    Status