CLOSER-Cohorts/archivist

View on GitHub
lib/importers/xml/ddi/instrument.rb

Summary

Maintainability
F
3 days
Test Coverage

Method has too many lines. [143/30]
Open

    def read_sequence_children(node, parent, branch = nil)
      position_counter = 0

      sub_sequence = lambda do |node, search, cc, branch|
        ref = node.at_xpath(search)
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

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

    def read_sequence_children(node, parent, branch = nil)
      position_counter = 0

      sub_sequence = lambda do |node, search, cc, branch|
        ref = node.at_xpath(search)
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb - About 1 day 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

Class has too many lines. [263/250]
Open

  class Instrument < DdiImporterBase
    def initialize(thing, options = {})
      if thing.is_a? String
        @doc = open(thing) { |f| Nokogiri::XML(f) }
      else
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method read_sequence_children has 143 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def read_sequence_children(node, parent, branch = nil)
      position_counter = 0

      sub_sequence = lambda do |node, search, cc, branch|
        ref = node.at_xpath(search)
Severity: Major
Found in lib/importers/xml/ddi/instrument.rb - About 5 hrs to fix

Cyclomatic complexity for read_sequence_children is too high. [25/6]
Open

    def read_sequence_children(node, parent, branch = nil)
      position_counter = 0

      sub_sequence = lambda do |node, search, cc, branch|
        ref = node.at_xpath(search)
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

File instrument.rb has 290 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Importers::XML::DDI
  class Instrument < DdiImporterBase
    def initialize(thing, options = {})
      if thing.is_a? String
        @doc = open(thing) { |f| Nokogiri::XML(f) }
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb - About 2 hrs to fix

Method build_instrument has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def self.build_instrument(doc, options= {}, instrument_importer=nil)
      save = defined?(options[:save]) ? true : options[:save]
      duplicate = defined?(options[:duplicate]) ? :do_nothing : options[:duplicate]

      i = ::Instrument.new
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb - About 2 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 has too many lines. [37/30]
Open

    def self.build_instrument(doc, options= {}, instrument_importer=nil)
      save = defined?(options[:save]) ? true : options[:save]
      duplicate = defined?(options[:duplicate]) ? :do_nothing : options[:duplicate]

      i = ::Instrument.new
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

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.

Cyclomatic complexity for build_instrument is too high. [11/6]
Open

    def self.build_instrument(doc, options= {}, instrument_importer=nil)
      save = defined?(options[:save]) ? true : options[:save]
      duplicate = defined?(options[:duplicate]) ? :do_nothing : options[:duplicate]

      i = ::Instrument.new
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Cyclomatic complexity for import is too high. [9/6]
Open

    def import(options = {})
      options.symbolize_keys!

      if options.has_key? :import_id
        @import = Import.find_by_id(options[:import_id])
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

    def import(options = {})
      options.symbolize_keys!

      if options.has_key? :import_id
        @import = Import.find_by_id(options[:import_id])
Severity: Minor
Found in lib/importers/xml/ddi/instrument.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 build_instrument has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.build_instrument(doc, options= {}, instrument_importer=nil)
      save = defined?(options[:save]) ? true : options[:save]
      duplicate = defined?(options[:duplicate]) ? :do_nothing : options[:duplicate]

      i = ::Instrument.new
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

            if (label = child.at_xpath('./Label/Content')).nil?
              cc_q.label = label
            else
              cc_q.label = 'Missing label'
            end
Severity: Major
Found in lib/importers/xml/ddi/instrument.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

          rescue
            cc_c.logic = ''
Severity: Major
Found in lib/importers/xml/ddi/instrument.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

        elsif child.name == 'Loop'

          cc_l = CcLoop.new(urn: extract_urn_identifier(child))
          @instrument.cc_loops << cc_l
          start_node = child.at_xpath('./InitialValue/Command/CommandContent')
Severity: Major
Found in lib/importers/xml/ddi/instrument.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

          rescue
            if (label = child.at_xpath('./Label/Content')).nil?
              cc_c.label = label
            else
              cc_c.label = 'Missing label'
Severity: Major
Found in lib/importers/xml/ddi/instrument.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

          rescue
            cc_c.literal = 'Missing text'
Severity: Major
Found in lib/importers/xml/ddi/instrument.rb - About 45 mins to fix

Avoid more than 4 levels of block nesting.
Open

              if duplicate == :update
                i = instruments.first
              else
                instruments.first.destroy
              end
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Shadowing outer local variable - branch.
Open

      sub_sequence = lambda do |node, search, cc, branch|
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
Open

    def initialize(thing, options = {})
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Shadowing outer local variable - node.
Open

      sub_sequence = lambda do |node, search, cc, branch|
Severity: Minor
Found in lib/importers/xml/ddi/instrument.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

There are no issues that match your filters.

Category
Status