SpeciesFileGroup/taxonworks

View on GitHub
app/models/depiction.rb

Summary

Maintainability
A
25 mins
Test Coverage

Method destroy_image_stub_collection_object has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def destroy_image_stub_collection_object
    if sqed_depiction.present?
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
Severity: Minor
Found in app/models/depiction.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

Use find_by instead of where.first.
Open

    if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first
Severity: Minor
Found in app/models/depiction.rb by rubocop

This cop is used to identify usages of where.first and change them to use find_by instead.

Example:

# bad
User.where(name: 'Bruce').first
User.where(name: 'Bruce').take

# good
User.find_by(name: 'Bruce')

Prefer the new style validations validates :column, presence: value over validates_presence_of.
Open

  validates_presence_of :depiction_object
Severity: Minor
Found in app/models/depiction.rb by rubocop

This cop checks for the use of old-style attribute validation macros.

Example:

# bad
validates_acceptance_of :foo
validates_confirmation_of :foo
validates_exclusion_of :foo
validates_format_of :foo
validates_inclusion_of :foo
validates_length_of :foo
validates_numericality_of :foo
validates_presence_of :foo
validates_absence_of :foo
validates_size_of :foo
validates_uniqueness_of :foo

# good
validates :foo, acceptance: true
validates :foo, confirmation: true
validates :foo, exclusion: true
validates :foo, format: true
validates :foo, inclusion: true
validates :foo, length: true
validates :foo, numericality: true
validates :foo, presence: true
validates :foo, absence: true
validates :foo, size: true
validates :foo, uniqueness: true

Prefer the new style validations validates :column, uniqueness: value over validates_uniqueness_of.
Open

  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}
Severity: Minor
Found in app/models/depiction.rb by rubocop

This cop checks for the use of old-style attribute validation macros.

Example:

# bad
validates_acceptance_of :foo
validates_confirmation_of :foo
validates_exclusion_of :foo
validates_format_of :foo
validates_inclusion_of :foo
validates_length_of :foo
validates_numericality_of :foo
validates_presence_of :foo
validates_absence_of :foo
validates_size_of :foo
validates_uniqueness_of :foo

# good
validates :foo, acceptance: true
validates :foo, confirmation: true
validates :foo, exclusion: true
validates :foo, format: true
validates :foo, inclusion: true
validates :foo, length: true
validates :foo, numericality: true
validates :foo, presence: true
validates :foo, absence: true
validates :foo, size: true
validates :foo, uniqueness: true

There are no issues that match your filters.

Category
Status