SpeciesFileGroup/taxonworks

View on GitHub
lib/material.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method create_quick_verbatim has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  def self.create_quick_verbatim(options  = {})
    # We could refactor this to use nested attributes, but it's not that much cleaner
    opts = {
      'collection_objects' => {},
      'note' => nil,
Severity: Minor
Found in lib/material.rb - About 3 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 create_quick_verbatim has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.create_quick_verbatim(options  = {})
    # We could refactor this to use nested attributes, but it's not that much cleaner
    opts = {
      'collection_objects' => {},
      'note' => nil,
Severity: Minor
Found in lib/material.rb - About 1 hr to fix

    Method save has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def save
          if collection_objects.size == 0
            errors = ActiveModel::Errors.new('base')
            errors.add(:total, 'No totals provided!')
            return false, errors
    Severity: Minor
    Found in lib/material.rb - About 55 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 duplicate_with_locks has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def duplicate_with_locks
          n = QuickVerbatimResponse.new(form_params)
          # nullify if not locked
          #
          n.repository = nil if !locked?('repository')
    Severity: Minor
    Found in lib/material.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

    Use opts['repository']['id'].present? instead of !opts['repository']['id'].blank?.
    Open

        repository = Repository.find(opts['repository']['id']) if opts['repository'] && !opts['repository']['id'].blank?
    Severity: Minor
    Found in lib/material.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?

    Use opts['preparation_type']['id'].present? instead of !opts['preparation_type']['id'].blank?.
    Open

        preparation_type = PreparationType.find(opts['preparation_type']['id']) if opts['preparation_type'] && !opts['preparation_type']['id'].blank?
    Severity: Minor
    Found in lib/material.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?

    Use opts['note']['text'].present? instead of !opts['note']['text'].blank?.
    Open

        note = Note.new(opts['note']) if opts['note'] && !opts['note']['text'].blank?
    Severity: Minor
    Found in lib/material.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?

    Use form_params['repository']['id'].present? instead of !form_params['repository']['id'].blank?.
    Open

          @repository = Repository.find(form_params['repository']['id']) if (form_params['repository'] && !form_params['repository']['id'].blank?)
    Severity: Minor
    Found in lib/material.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?

    Use opts['collection_objects'][k]['total'].present? instead of !opts['collection_objects'][k]['total'].blank?.
    Open

          objects.merge!(k => opts['collection_objects'][k]) if !opts['collection_objects'][k]['total'].blank?
    Severity: Minor
    Found in lib/material.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?

    Use opts['identifier']['namespace_id'].present? instead of !opts['identifier']['namespace_id'].blank?.
    Open

        if opts['identifier'] && !opts['identifier']['namespace_id'].blank? && !opts['identifier']['identifier'].blank?
    Severity: Minor
    Found in lib/material.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?

    Use opts['identifier']['identifier'].present? instead of !opts['identifier']['identifier'].blank?.
    Open

        if opts['identifier'] && !opts['identifier']['namespace_id'].blank? && !opts['identifier']['identifier'].blank?
    Severity: Minor
    Found in lib/material.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?

    Use form_params['preparation_type']['id'].present? instead of !form_params['preparation_type']['id'].blank?.
    Open

          @preparation_type = PreparationType.find(form_params['preparation_type']['id']) if (form_params['preparation_type'] && !form_params['preparation_type']['id'].blank?)
    Severity: Minor
    Found in lib/material.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?

    There are no issues that match your filters.

    Category
    Status