rviney/ig_markets

View on GitHub

Showing 14 of 14 total issues

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

        def validate_trailing_stop_constraints
          if trailing_stop
            raise ArgumentError, 'do not set stop_level when trailing_stop is true' if stop_level
            raise ArgumentError, 'set stop_distance when trailing_stop is true' unless stop_distance
            raise ArgumentError, 'set trailing_stop_increment when trailing_stop is true' unless trailing_stop_increment
Severity: Minor
Found in lib/ig_markets/dealing_platform/position_methods.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 instantiate_model_from_attributes_hash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def instantiate_model_from_attributes_hash(model_class, attributes)
      model_class.new.tap do |model|
        model.instance_variable_set :@dealing_platform, self

        attributes.each do |attribute, value|
Severity: Minor
Found in lib/ig_markets/dealing_platform.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

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

        def parse_date_time(attributes, attribute, klass, format, display_format)
Severity: Minor
Found in lib/ig_markets/cli/main.rb - About 35 mins to fix

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

            def cell_color(_value, sprint, _row_index, column_index)
              return unless headings[column_index] == 'Payout'
    
              if current_level(sprint) > sprint.strike_level && sprint.direction == :buy ||
                 current_level(sprint) < sprint.strike_level && sprint.direction == :sell
    Severity: Minor
    Found in lib/ig_markets/cli/tables/sprint_market_positions_table.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 begin_session has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

            def begin_session(options)
              platform = options[:demo] ? :demo : :live
    
              @dealing_platform ||= DealingPlatform.new
              @dealing_platform.session.log_sinks = [$stdout] if options[:verbose]
    Severity: Minor
    Found in lib/ig_markets/cli/main.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 filter_options has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

            def filter_options(options, whitelist)
              options.each_with_object({}) do |(key, value), new_hash|
                next unless whitelist.include? key.to_sym
    
                new_hash[key.to_sym] = value == key ? nil : value
    Severity: Minor
    Found in lib/ig_markets/cli/main.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 on_market_update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def on_market_update(market_update)
            market_models.each do |model|
              next unless model.market.epic == market_update.epic
    
              attributes_to_copy = { bid: :bid, high: :high, low: :low, net_change: :change, offer: :offer,
    Severity: Minor
    Found in lib/ig_markets/streaming/account_state.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 build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.build(error_code)
          if API_ERROR_CODE_TO_CLASS.key? error_code
            API_ERROR_CODE_TO_CLASS[error_code].new ''
          else
            @reported_unrecognized_error_codes ||= []
    Severity: Minor
    Found in lib/ig_markets/errors.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 process_response has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def process_response(response, options)
          body = parse_body response
    
          if body.is_a?(Hash) && body.key?(:error_code)
            error = IGMarketsError.build body[:error_code]
    Severity: Minor
    Found in lib/ig_markets/session.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 parse_date_time has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def parse_date_time(attributes, attribute, klass, format, display_format)
              return unless attributes.key? attribute
    
              if !['', attribute.to_s].include? attributes[attribute].to_s
                begin
    Severity: Minor
    Found in lib/ig_markets/cli/main.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 validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def validate
              required = %i[currency_code direction epic guaranteed_stop level size time_in_force type]
              required.each do |attribute|
                raise ArgumentError, "#{attribute} attribute must be set" if send(attribute).nil?
              end
    Severity: Minor
    Found in lib/ig_markets/dealing_platform/working_order_methods.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 historical_price_result has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def historical_price_result(dealing_platform)
            market = dealing_platform.markets[options[:epic]]
    
            raise ArgumentError, 'invalid EPIC' unless market
    
    
    Severity: Minor
    Found in lib/ig_markets/cli/commands/prices_command.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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

          def on_market_data(item_name, item_data, new_data)
            item_data = @dealing_platform.instantiate_models MarketUpdate, item_data
            new_data = @dealing_platform.instantiate_models MarketUpdate, new_data
    
            item_data.epic = item_name.match(MARKET_DATA_REGEX).captures.first
    Severity: Minor
    Found in lib/ig_markets/streaming/subscription.rb and 1 other location - About 15 mins to fix
    lib/ig_markets/streaming/subscription.rb on lines 65..72

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 26.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

          def on_account_data(item_name, item_data, new_data)
            item_data = @dealing_platform.instantiate_models AccountUpdate, item_data
            new_data = @dealing_platform.instantiate_models AccountUpdate, new_data
    
            item_data.account_id = item_name.match(ACCOUNT_DATA_REGEX).captures.first
    Severity: Minor
    Found in lib/ig_markets/streaming/subscription.rb and 1 other location - About 15 mins to fix
    lib/ig_markets/streaming/subscription.rb on lines 75..82

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 26.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Severity
    Category
    Status
    Source
    Language