ManageIQ/ffi-vix_disk_lib

View on GitHub
lib/ffi-vix_disk_lib/safe_connect_params.rb

Summary

Maintainability
A
1 hr
Test Coverage
F
47%

Method initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(in_conn_parms)
        conn_parms      = FFI::MemoryPointer.new(API::ConnectParams, 1, true)
        @connect_params = conn_parms
        set_param(in_conn_parms, :vmxSpec)
        # Increment structure pointer to server_name
Severity: Minor
Found in lib/ffi-vix_disk_lib/safe_connect_params.rb - About 35 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 read has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def self.read(ffi_connect_parms)
        out_connect_parms              = {}
        spec_ptr                       =  ffi_connect_parms.get_pointer(API::ConnectParams.offset_of(:vmxSpec))
        out_connect_parms[:vmxSpec]    = spec_ptr.read_string unless spec_ptr.null?
        serv_ptr                       =  ffi_connect_parms.get_pointer(API::ConnectParams.offset_of(:serverName))
Severity: Minor
Found in lib/ffi-vix_disk_lib/safe_connect_params.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

private (on line 85) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
Open

      def self.read_safe_str_from_mem(mem_ptr)

Checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

Example:

# bad

class C
  private

  def self.method
    puts 'hi'
  end
end

Example:

# good

class C
  def self.method
    puts 'hi'
  end

  private_class_method :method
end

Example:

# good

class C
  class << self
    private

    def method
      puts 'hi'
    end
  end
end

Variable @connect_params used in void context.
Open

        @connect_params

Checks for operators, variables, literals, lambda, proc and nonmutating methods used in void context.

Example: CheckForMethodsWithNoSideEffects: false (default)

# bad
def some_method
  some_num * 10
  do_something
end

def some_method(some_var)
  some_var
  do_something
end

Example: CheckForMethodsWithNoSideEffects: true

# bad
def some_method(some_array)
  some_array.sort
  do_something(some_array)
end

# good
def some_method
  do_something
  some_num * 10
end

def some_method(some_var)
  do_something
  some_var
end

def some_method(some_array)
  some_array.sort!
  do_something(some_array)
end

There are no issues that match your filters.

Category
Status