ManageIQ/manageiq-appliance_console

View on GitHub
lib/manageiq/appliance_console/database_configuration.rb

Summary

Maintainability
C
1 day
Test Coverage
B
81%

Class DatabaseConfiguration has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

  class DatabaseConfiguration
    include ManageIQ::ApplianceConsole::ManageiqUserMixin

    attr_accessor :adapter, :host, :username, :database, :port, :region, :run_as_evm_server
    attr_reader :password
Severity: Minor
Found in lib/manageiq/appliance_console/database_configuration.rb - About 3 hrs to fix

Method ask_for_database_credentials has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    def ask_for_database_credentials(password_twice = true)
      self.host     = ask_for_ip_or_hostname("database hostname or IP address", host) if host.blank? || !local?
      self.port     = ask_for_integer("port number", nil, port) unless local?
      self.database = just_ask("name of the database on #{host}", database) unless local?
      self.username = just_ask("username", username) unless local?
Severity: Minor
Found in lib/manageiq/appliance_console/database_configuration.rb - About 3 hrs 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 ask_for_database_credentials has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def ask_for_database_credentials(password_twice = true)
      self.host     = ask_for_ip_or_hostname("database hostname or IP address", host) if host.blank? || !local?
      self.port     = ask_for_integer("port number", nil, port) unless local?
      self.database = just_ask("name of the database on #{host}", database) unless local?
      self.username = just_ask("username", username) unless local?
Severity: Minor
Found in lib/manageiq/appliance_console/database_configuration.rb - About 1 hr to fix

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

    def run_interactive
      ask_questions

      clear_screen
      say "Activating the configuration using the following settings...\n#{friendly_inspect}\n"
Severity: Minor
Found in lib/manageiq/appliance_console/database_configuration.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 initialize_from_hash has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize_from_hash(hash)
      hash.each do |k, v|
        next if v.nil?
        setter = "#{k}="
        if self.respond_to?(setter)
Severity: Minor
Found in lib/manageiq/appliance_console/database_configuration.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

Method load_current has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def self.load_current
      require 'yaml'
      unless File.exist?(DB_YML)
        require 'fileutils'
        FileUtils.cp(DB_YML_TMPL, DB_YML) if File.exist?(DB_YML_TMPL)
Severity: Minor
Found in lib/manageiq/appliance_console/database_configuration.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 239) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
Open

    def self.load_current

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

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

    def self.encrypt_decrypt_password(settings)

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

There are no issues that match your filters.

Category
Status