ManageIQ/manageiq-consumption

View on GitHub
app/models/manageiq/showback/tier.rb

Summary

Maintainability
A
25 mins
Test Coverage
A
100%

Method validate_interval has a Cognitive Complexity of 12 (exceeds 11 allowed). Consider refactoring.
Open

    def validate_interval
      raise _("Start value of interval is greater than end value") unless tier_start_value < tier_end_value
      ManageIQ::Showback::Tier.where(:rate => rate).each do |tier|
        # Returns true == overlap, false == no overlap
        next unless self != tier
Severity: Minor
Found in app/models/manageiq/showback/tier.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

Wrap expressions with varying precedence with parentheses to avoid ambiguity.
Open

      starts_with_zero? && value.zero? || value > tier_start_value && value.to_f <= tier_end_value

Looks for expressions containing multiple binary operators where precedence is ambiguous due to lack of parentheses. For example, in 1 + 2 * 3, the multiplication will happen before the addition, but lexically it appears that the addition will happen first.

The cop does not consider unary operators (ie. !a or -b) or comparison operators (ie. a =~ b) because those are not ambiguous.

NOTE: Ranges are handled by Lint/AmbiguousRange.

Example:

# bad
a + b * c
a || b && c
a ** b + c

# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c

# good (same precedence)
a + b + c
a * b / c % d

Wrap expressions with varying precedence with parentheses to avoid ambiguity.
Open

      starts_with_zero? && value.zero? || value > tier_start_value && value.to_f <= tier_end_value

Looks for expressions containing multiple binary operators where precedence is ambiguous due to lack of parentheses. For example, in 1 + 2 * 3, the multiplication will happen before the addition, but lexically it appears that the addition will happen first.

The cop does not consider unary operators (ie. !a or -b) or comparison operators (ie. a =~ b) because those are not ambiguous.

NOTE: Ranges are handled by Lint/AmbiguousRange.

Example:

# bad
a + b * c
a || b && c
a ** b + c

# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c

# good (same precedence)
a + b + c
a * b / c % d

There are no issues that match your filters.

Category
Status