ManageIQ/manageiq-ui-classic

View on GitHub
app/helpers/number_helper.rb

Summary

Maintainability
A
1 hr
Test Coverage
A
95%

Method human_size_to_rails_method has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def human_size_to_rails_method(size)
    s = size.dup
    if size.ends_with?(" Byte")
      s[-5..-1] = ""
    elsif size.ends_with?(" Bytes")
Severity: Minor
Found in app/helpers/number_helper.rb - About 55 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

Method mhz_to_human_size has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def mhz_to_human_size(size, *args)
    precision = args.first
    precision = precision[:precision] if precision.kind_of?(Hash)
    precision ||= 1

Severity: Minor
Found in app/helpers/number_helper.rb - About 55 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

      s = s.abs * 1000**2
Severity: Minor
Found in app/helpers/number_helper.rb by rubocop

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