app/models/taxon_name_relationship/iczn.rb
Method sv_validate_priority
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def sv_validate_priority
if self.type_class.nomenclatural_priority == :direct
date1 = self.subject_taxon_name.cached_nomenclature_date
date2 = self.object_taxon_name.cached_nomenclature_date
if !!date1 && !!date2 && date2 > date1 && subject_invalid_statuses.empty?
- Read upRead up
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
Prefer the new style validations validates :column, uniqueness: value
over validates_uniqueness_of
. Open
Open
validates_uniqueness_of :subject_taxon_name_id, scope: [:type, :object_taxon_name_id]
- Read upRead up
- Exclude checks
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