cantino/huginn

View on GitHub
app/importers/scenario_import.rb

Summary

Maintainability
C
1 day
Test Coverage

Method import has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

  def import(options = {})
    success = true
    guid = parsed_data['guid']
    description = parsed_data['description']
    name = parsed_data['name']
Severity: Minor
Found in app/importers/scenario_import.rb - About 4 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

Method import has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def import(options = {})
    success = true
    guid = parsed_data['guid']
    description = parsed_data['description']
    name = parsed_data['name']
Severity: Minor
Found in app/importers/scenario_import.rb - About 1 hr to fix

    Method generate_diff has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def generate_diff
        @agent_diffs = (parsed_data['agents'] || []).map.with_index do |agent_data, index|
          # AgentDiff is defined at the end of this file.
          agent_diff = AgentDiff.new(agent_data, parsed_data['schema_version'])
          if existing_scenario
    Severity: Minor
    Found in app/importers/scenario_import.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 diff_with! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def diff_with!(agent)
          return unless agent.present?
    
          self.agent = agent
    
    
    Severity: Minor
    Found in app/importers/scenario_import.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 validate_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def validate_data
        if data.present?
          @parsed_data = JSON.parse(data) rescue {}
          if (%w[name guid agents] - @parsed_data.keys).length > 0
            errors.add(:base, "The provided data does not appear to be a valid Scenario.")
    Severity: Minor
    Found in app/importers/scenario_import.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 store! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def store!(agent_data)
          self.type = FieldDiff.new(agent_data["type"].split("::").pop)
          self.options = FieldDiff.new(agent_data['options'] || {})
          BASE_FIELDS.each do |option|
            if agent_data.has_key?(option)
    Severity: Minor
    Found in app/importers/scenario_import.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 each_field has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def each_field
          boolean = [["True", "true"], ["False", "false"]]
          yield 'name', name if name.requires_merge?
          yield 'schedule', schedule, Agent::SCHEDULES.map {|s| [AgentHelper.builtin_schedule_name(s), s] } if self['schedule'].present? && schedule.requires_merge?
          yield 'keep_events_for', keep_events_for, Agent::EVENT_RETENTION_SCHEDULES if self['keep_events_for'].present? && keep_events_for.requires_merge?
    Severity: Minor
    Found in app/importers/scenario_import.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

            links.each do |link|
              receiver = created_agents[link['receiver']]
              source = created_agents[link['source']]
              receiver.sources << source unless receiver.sources.include?(source)
    Severity: Minor
    Found in app/importers/scenario_import.rb and 1 other location - About 15 mins to fix
    app/importers/scenario_import.rb on lines 101..104

    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

            control_links.each do |control_link|
              controller = created_agents[control_link['controller']]
              control_target = created_agents[control_link['control_target']]
              controller.control_targets << control_target unless controller.control_targets.include?(control_target)
    Severity: Minor
    Found in app/importers/scenario_import.rb and 1 other location - About 15 mins to fix
    app/importers/scenario_import.rb on lines 95..98

    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

    There are no issues that match your filters.

    Category
    Status