SpeciesFileGroup/taxonworks

View on GitHub
lib/batch_load/import/otus.rb

Summary

Maintainability
A
1 hr
Test Coverage

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

    def build_otus
      # test_build
      build_objects = {}
      i = 1 # accounting for headers
      csv.each do |row|
Severity: Minor
Found in lib/batch_load/import/otus.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

Use if otu_attributes[:name].present? instead of unless otu_attributes[:name].blank?.
Open

          unless otu_attributes[:name].blank?
Severity: Minor
Found in lib/batch_load/import/otus.rb by rubocop

This cop checks for code that can be written with simpler conditionals using Object#present? defined by Active Support.

Interaction with Style/UnlessElse: The configuration of NotBlank will not produce an offense in the context of unless else if Style/UnlessElse is inabled. This is to prevent interference between the auto-correction of the two cops.

Example: NotNilAndNotEmpty: true (default)

# Converts usages of `!nil? && !empty?` to `present?`

# bad
!foo.nil? && !foo.empty?

# bad
foo != nil && !foo.empty?

# good
foo.present?

Example: NotBlank: true (default)

# Converts usages of `!blank?` to `present?`

# bad
!foo.blank?

# bad
not foo.blank?

# good
foo.present?

Example: UnlessBlank: true (default)

# Converts usages of `unless blank?` to `if present?`

# bad
something unless foo.blank?

# good
something if foo.present?

TODO found
Open

        begin # processing the Otu !! TODO: if there is no rescue there is no point?
Severity: Minor
Found in lib/batch_load/import/otus.rb by fixme

TODO found
Open

  # TODO: Originally transliterated from Import::CollectionObjects: Remove this to-do after successful operation.
Severity: Minor
Found in lib/batch_load/import/otus.rb by fixme

Freeze mutable objects assigned to constants.
Open

    SAVE_ORDER = [:otu]
Severity: Minor
Found in lib/batch_load/import/otus.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Strict mode can be used to freeze all constants, rather than just literals. Strict mode is considered an experimental feature. It has not been updated with an exhaustive list of all methods that will produce frozen objects so there is a decent chance of getting some false positives. Luckily, there is no harm in freezing an already frozen object.

Example: EnforcedStyle: literals (default)

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

# good
CONST = <<~TESTING.freeze
  This is a heredoc
TESTING

# good
CONST = Something.new

Example: EnforcedStyle: strict

# bad
CONST = Something.new

# bad
CONST = Struct.new do
  def foo
    puts 1
  end
end

# good
CONST = Something.new.freeze

# good
CONST = Struct.new do
  def foo
    puts 1
  end
end.freeze

There are no issues that match your filters.

Category
Status