ManageIQ/manageiq

View on GitHub
lib/vmdb/loggers.rb

Summary

Maintainability
A
45 mins
Test Coverage
A
100%

Method ensure_log_file_permissions! has a Cognitive Complexity of 14 (exceeds 11 allowed). Consider refactoring.
Open

    private_class_method def self.ensure_log_file_permissions!(log_file)
      return unless log_file.kind_of?(Pathname)
      return if !MiqEnvironment::Command.is_appliance? || MiqEnvironment::Command.is_podified?

      file_perm = 0o660 # Allow members of the manageiq group to write to log files
Severity: Minor
Found in lib/vmdb/loggers.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

Sort files before requiring them.
Open

Dir.glob(File.join(File.dirname(__FILE__), "loggers", "*")).each { |f| require f }
Severity: Minor
Found in lib/vmdb/loggers.rb by rubocop

Dir[...] and Dir.glob(...) do not make any guarantees about the order in which files are returned. The final order is determined by the operating system and file system. This means that using them in cases where the order matters, such as requiring files, can lead to intermittent failures that are hard to debug. To ensure this doesn't happen, always sort the list.

Example:

# bad
Dir["./lib/**/*.rb"].each do |file|
  require file
end

# good
Dir["./lib/**/*.rb"].sort.each do |file|
  require file
end

Example:

# bad
Dir.glob(Rails.root.join(__dir__, 'test', '*.rb')) do |file|
  require file
end

# good
Dir.glob(Rails.root.join(__dir__, 'test', '*.rb')).sort.each do |file|
  require file
end

Do not suppress exceptions.
Open

    rescue Errno::EPERM
Severity: Minor
Found in lib/vmdb/loggers.rb by rubocop

This cop checks for rescue blocks with no body.

Example:

# bad
def some_method
  do_something
rescue
end

# bad
begin
  do_something
rescue
end

# good
def some_method
  do_something
rescue
  handle_exception
end

# good
begin
  do_something
rescue
  handle_exception
end

Example: AllowComments: true (default)

# good
def some_method
  do_something
rescue
  # do nothing
end

# good
begin
  do_something
rescue
  # do nothing
end

Example: AllowComments: false

# bad
def some_method
  do_something
rescue
  # do nothing
end

# bad
begin
  do_something
rescue
  # do nothing
end

There are no issues that match your filters.

Category
Status