SpeciesFileGroup/taxonworks

View on GitHub
app/helpers/observation_matrices/export/otu_contents_helper.rb

Summary

Maintainability
D
2 days
Test Coverage

Method has too many lines. [138/25]
Open

  def get_otu_contents(options = {})
    opt = {otus: []}.merge!(options)
    m = opt[:observation_matrix]

    otus = Otu.select('otus.*, observation_matrix_rows.id AS row_id').

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

  def get_otu_contents(options = {})
    opt = {otus: []}.merge!(options)
    m = opt[:observation_matrix]

    otus = Otu.select('otus.*, observation_matrix_rows.id AS row_id').
Severity: Minor
Found in app/helpers/observation_matrices/export/otu_contents_helper.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

Method get_otu_contents has 138 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def get_otu_contents(options = {})
    opt = {otus: []}.merge!(options)
    m = opt[:observation_matrix]

    otus = Otu.select('otus.*, observation_matrix_rows.id AS row_id').
Severity: Major
Found in app/helpers/observation_matrices/export/otu_contents_helper.rb - About 5 hrs to fix

    Use if lbl.present? instead of unless lbl.blank?.
    Open

                  list += "<b>Label:</b> #{lbl}<br>\n" unless lbl.blank?

    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?

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

                  lbl.push(descriptors[index][:name]) unless descriptors[index][:name].blank?

    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?

    Use if list.present? instead of unless list.blank?.
    Open

              csv << ['row_' + otu_rows[object[1][:otu_id]].to_s, 'Illustrations', list ] unless list.blank?

    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?

    Use if cit.present? instead of unless cit.blank?.
    Open

                  list += "<b>Citation:</b> #{cit}<br>\n" unless cit.blank?

    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?

    Use if depiction[:caption].present? instead of unless depiction[:caption].blank?.
    Open

                  lbl.push(depiction[:caption]) unless depiction[:caption].blank?

    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?

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

                  if im.image_hash[depiction[:image_id]][:image_file_content_type] == 'image/tiff'
                    href = im.image_hash[depiction[:image_id]][:medium_url]
                  else
                    href = im.image_hash[depiction[:image_id]][:original_url]
    Severity: Minor
    Found in app/helpers/observation_matrices/export/otu_contents_helper.rb and 1 other location - About 25 mins to fix
    app/helpers/observation_matrices/export/nexml_helper.rb on lines 227..230

    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 29.

    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