SpeciesFileGroup/taxonworks

View on GitHub
app/models/descriptor.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Method target_name has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def target_name(target, language_id)
    n = self.name
    a = nil
    case target
    when :key
Severity: Minor
Found in app/models/descriptor.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

Specify a :dependent option.
Open

  has_many :observation_matrix_columns, inverse_of: :descriptor
Severity: Minor
Found in app/models/descriptor.rb by rubocop

This cop looks for has_many or has_one associations that don't specify a :dependent option. It doesn't register an offense if :through option was specified.

Example:

# bad
class User < ActiveRecord::Base
  has_many :comments
  has_one :avatar
end

# good
class User < ActiveRecord::Base
  has_many :comments, dependent: :restrict_with_exception
  has_one :avatar, dependent: :destroy
  has_many :patients, through: :appointments
end

TODO found
Open

  # TODO: get rid of this
Severity: Minor
Found in app/models/descriptor.rb by fixme

TODO found
Open

  # TODO: these should be `is_` to follow design pattern
Severity: Minor
Found in app/models/descriptor.rb by fixme

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

  def target_name(target, language_id)
    n = self.name
    a = nil
    case target
    when :key
Severity: Major
Found in app/models/descriptor.rb and 1 other location - About 2 hrs to fix
app/models/character_state.rb on lines 45..69

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

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

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

  validates_presence_of :name, :type
Severity: Minor
Found in app/models/descriptor.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