ManageIQ/manageiq-gems-pending

View on GitHub

Showing 216 of 216 total issues

File xml_hash.rb has 461 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rexml/document'
require 'active_support/core_ext/hash/keys'

module XmlHash
  class Element < Hash
Severity: Minor
Found in lib/gems/pending/util/xml/xml_hash.rb - About 7 hrs to fix

Class MiqGenericMountSession has 45 methods (exceeds 20 allowed). Consider refactoring.
Open

class MiqGenericMountSession < MiqFileStorage::Interface
  class NoSuchFileOrDirectory < RuntimeError; end

  class << self
    def run_command(command, args)
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb - About 6 hrs to fix

Method disk_usage has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

  def self.disk_usage(file = nil)
    file = normalize_df_file_argument(file)

    case Sys::Platform::IMPL
    when :linux
Severity: Minor
Found in lib/gems/pending/util/miq-system.rb - About 6 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

Class Element has 43 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Element < Hash
    include Enumerable

    def initialize(name, attrs = {}, parent = nil)
      super()
Severity: Minor
Found in lib/gems/pending/util/xml/xml_hash.rb - About 5 hrs to fix

File miq_generic_mount_session.rb has 397 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'active_support/core_ext/object/blank'
require 'fileutils'
require 'logger'
require 'sys-uname'
require 'uri'
Severity: Minor
Found in lib/gems/pending/util/mount/miq_generic_mount_session.rb - About 5 hrs to fix

Method miq_patch_elements has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  def miq_patch_elements(xml, patch, node, direction, stats)
    miq_patch_element_logging(node, direction)
    patch.root.elements[node.to_s].each_element do |e|
      path = e.elements['path'].elements[1]
      data = e.elements['data'].elements[1]
Severity: Minor
Found in lib/gems/pending/util/xml/xml_patch.rb - About 4 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

Class Document has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Document < Hash
    include MiqXmlDiff
    include MiqXmlPatch

    def initialize(name = "xml", _attrs = {}, _parent = nil)
Severity: Minor
Found in lib/gems/pending/util/xml/xml_hash.rb - About 3 hrs to fix

Class MiqIPMI has 26 methods (exceeds 20 allowed). Consider refactoring.
Open

class MiqIPMI
  def initialize(server = nil, username = nil, password = nil)
    @server = server
    @username = username
    @password = password
Severity: Minor
Found in lib/gems/pending/util/miq-ipmi.rb - About 3 hrs to fix

Method parse_output has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def parse_output(cmd_text)
    last_key = nil
    lines = cmd_text.kind_of?(Array) ? cmd_text : cmd_text.split("\n")
    lines.inject({}) do |a, line|
      idx = line.index(": ")
Severity: Minor
Found in lib/gems/pending/util/miq-ipmi.rb - About 2 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

File miq_rexml.rb has 273 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'time'
require 'rexml/document'
require_relative 'xml_utils'

class MIQRexml
Severity: Minor
Found in lib/gems/pending/util/xml/miq_rexml.rb - About 2 hrs to fix

Cyclomatic complexity for disk_usage is too high. [18/11]
Open

  def self.disk_usage(file = nil)
    file = normalize_df_file_argument(file)

    case Sys::Platform::IMPL
    when :linux
Severity: Minor
Found in lib/gems/pending/util/miq-system.rb by rubocop

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method walk has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def self.walk(node, parents = "")
    tags = []

    sep = "/"
    case node.name
Severity: Minor
Found in lib/gems/pending/util/xml/xml_utils.rb - About 2 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

Cyclomatic complexity for to_png is too high. [17/11]
Open

  def self.to_png(data, options = {})
    require 'gruff'

    graph = case options[:graph_type]
            when :line    then Gruff::Line.new

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

File miq-powershell.rb has 261 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'awesome_spawn'
require 'io/wait'
require 'open-uri'

# Not to be confused with our own win32 directory, this is in stdlib on windows
Severity: Minor
Found in lib/gems/pending/util/win32/miq-powershell.rb - About 2 hrs to fix

Method linux_process_stat has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.linux_process_stat(pid = nil)
    pid ||= Process.pid

    filename = "/proc/#{pid}/stat"
    raise Errno::ESRCH.new(pid.to_s) unless File.exist?(filename)
Severity: Major
Found in lib/gems/pending/util/miq-process.rb - About 2 hrs to fix

Method disk_usage has 53 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.disk_usage(file = nil)
    file = normalize_df_file_argument(file)

    case Sys::Platform::IMPL
    when :linux
Severity: Major
Found in lib/gems/pending/util/miq-system.rb - About 2 hrs to fix

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  def mount_share
    super

    log_header = "MIQ(#{self.class.name}-mount_share)"
    logger.info(
Severity: Major
Found in lib/gems/pending/util/mount/miq_glusterfs_session.rb and 1 other location - About 2 hrs to fix
lib/gems/pending/util/mount/miq_nfs_session.rb on lines 17..39

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 80.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  def mount_share
    super

    log_header = "MIQ(#{self.class.name}-mount_share)"
    logger.info("#{log_header} Connecting to host: [#{@host}], share: [#{@mount_path}] using mount point: [#{@mnt_point}]...")
Severity: Major
Found in lib/gems/pending/util/mount/miq_nfs_session.rb and 1 other location - About 2 hrs to fix
lib/gems/pending/util/mount/miq_glusterfs_session.rb on lines 18..39

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 80.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method convert_type has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def convert_type(c)
      case c.name.to_sym
      when :U16, :U32, :I32, :U64, :I64, :D, :By then c.text.to_i
      when :Db then c.text.to_f
      when :B then c.text.downcase == 'true'
Severity: Minor
Found in lib/gems/pending/util/win32/miq-powershell.rb - About 1 hr 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 miq_compare_elements has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def miq_compare_elements(node1, node2, delta, diff_elements, stats)
    node1.each_element do |e1|
      e2 = miq_find_element(e1, node2)
      if e2
        if miq_compare_attributes(e1, e2) == false
Severity: Minor
Found in lib/gems/pending/util/xml/xml_diff.rb - About 1 hr 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

Severity
Category
Status
Source
Language