SpeciesFileGroup/taxonworks

View on GitHub
app/validators/date_time_validator.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method validate_each has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(record, attribute, value)
    min_value = @min_value.respond_to?(:call) ? @min_value.call : @min_value
    max_value = @max_value.respond_to?(:call) ? @max_value.call : @max_value

    message ||= @message || options.fetch(:message, "must be an integer between #{min_value} and #{max_value}")
Severity: Minor
Found in app/validators/date_time_validator.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

Use value.present? instead of !value.blank?.
Open

    elsif !value.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?

There are no issues that match your filters.

Category
Status