ManageIQ/manageiq-smartstate

View on GitHub
lib/disk/modules/miq_disk_cache.rb

Summary

Maintainability
A
2 hrs
Test Coverage
A
90%

Method d_read_cached has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def d_read_cached(start_sector, number_sectors)
    $log.debug "MiqDiskCache.d_read_cached(#{start_sector}, #{number_sectors})"
    @block_cache.keys.each do |block_range|
      sector_offset = start_sector - block_range.first
      buffer_offset = sector_offset * @blockSize
Severity: Minor
Found in lib/disk/modules/miq_disk_cache.rb - About 1 hr to fix

Method d_read_cached has a Cognitive Complexity of 11 (exceeds 8 allowed). Consider refactoring.
Open

  def d_read_cached(start_sector, number_sectors)
    $log.debug "MiqDiskCache.d_read_cached(#{start_sector}, #{number_sectors})"
    @block_cache.keys.each do |block_range|
      sector_offset = start_sector - block_range.first
      buffer_offset = sector_offset * @blockSize
Severity: Minor
Found in lib/disk/modules/miq_disk_cache.rb - About 45 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

Use sum instead of reduce(:+), unless calling reduce(:+) on an empty array.
Open

    misses = @cache_misses.values.reduce(:+)
Severity: Minor
Found in lib/disk/modules/miq_disk_cache.rb by rubocop

Use sum instead of reduce(:+), unless calling reduce(:+) on an empty array.
Open

    hits   = @cache_hits.values.reduce(:+)
Severity: Minor
Found in lib/disk/modules/miq_disk_cache.rb by rubocop

Method MiqDiskCache#d_size is defined at both lib/disk/modules/miq_disk_cache.rb:10 and lib/disk/modules/miq_disk_cache.rb:32.
Open

  def d_size
Severity: Minor
Found in lib/disk/modules/miq_disk_cache.rb by rubocop

Checks for duplicated instance (or singleton) method definitions.

Example:

# bad

def foo
  1
end

def foo
  2
end

Example:

# bad

def foo
  1
end

alias foo bar

Example:

# good

def foo
  1
end

def bar
  2
end

Example:

# good

def foo
  1
end

alias bar foo

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

               @block_cache[block_range] +
               d_read_cached(block_range.last + 1, sectors_post_range)
Severity: Minor
Found in lib/disk/modules/miq_disk_cache.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