ManageIQ/manageiq-ui-classic

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
F
1 wk
Test Coverage
B
85%

File application_helper.rb has 1144 lines of code (exceeds 400 allowed). Consider refactoring.
Open

module ApplicationHelper
  include ApplicationHelper::ViewsShared
  include ApplicationHelper::Flash
  include ApplicationHelper::Listnav
  include ApplicationHelper::Navbar
Severity: Major
Found in app/helpers/application_helper.rb - About 2 days to fix

Method view_to_url has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

  def view_to_url(view, parent = nil)
    association = view_to_association(view, parent)
    if association.nil?
      controller, action = db_to_controller(view.db)
      if controller == "ems_cloud" && action == "show"
Severity: Minor
Found in app/helpers/application_helper.rb - About 1 day 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 view_to_url is too high. [40/11]
Open

  def view_to_url(view, parent = nil)
    association = view_to_association(view, parent)
    if association.nil?
      controller, action = db_to_controller(view.db)
      if controller == "ems_cloud" && action == "show"
Severity: Minor
Found in app/helpers/application_helper.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

Cyclomatic complexity for db_to_controller is too high. [32/11]
Open

  def db_to_controller(db, action = "show")
    action = "x_show" if @explorer
    case db
    when "ActionSet"
      controller = "miq_action"
Severity: Minor
Found in app/helpers/application_helper.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 view_to_url has 89 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def view_to_url(view, parent = nil)
    association = view_to_association(view, parent)
    if association.nil?
      controller, action = db_to_controller(view.db)
      if controller == "ems_cloud" && action == "show"
Severity: Major
Found in app/helpers/application_helper.rb - About 3 hrs to fix

Method db_to_controller has 85 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def db_to_controller(db, action = "show")
    action = "x_show" if @explorer
    case db
    when "ActionSet"
      controller = "miq_action"
Severity: Major
Found in app/helpers/application_helper.rb - About 3 hrs to fix

Method display_adv_search? has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def display_adv_search?
    %w[auth_key_pair_cloud
       storage_service
       storage_resource
       host_initiator
Severity: Major
Found in app/helpers/application_helper.rb - About 2 hrs to fix

Consider simplifying this complex logical expression.
Open

    if @edit && @edit[:expression] &&
       ((default_search?(search.name) || no_default_search?(search.id)) && expression_selected_nil_or_id(search.id) ||
        (@edit[:expression][:selected] && @edit[:expression][:selected][:id].zero? && search.id.to_i.zero? ||
         expression_selected_id_or_name(:name, search.name)))
      'active'
Severity: Critical
Found in app/helpers/application_helper.rb - About 1 hr to fix

Method javascript_for_timer_type has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def javascript_for_timer_type(timer_type)
    case timer_type
    when "Monthly"
      [
        javascript_hide("weekly_span"),
Severity: Minor
Found in app/helpers/application_helper.rb - About 1 hr to fix

Method _toolbar_builder has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def _toolbar_builder
    ToolbarBuilder.new(
      self,
      binding,
      :active           => @active,
Severity: Minor
Found in app/helpers/application_helper.rb - About 1 hr to fix

Method calculate_toolbars has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def calculate_toolbars
    toolbars = {}
    if display_back_button? # taskbar branch
      toolbars['summary_center_tb'] = controller.restful? ? "summary_center_restful_tb" : "summary_center_tb"
    end
Severity: Minor
Found in app/helpers/application_helper.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 show_taskbar_in_header? has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def show_taskbar_in_header?
    return false if @explorer
    return false if controller.action_name.end_with?("tagging_edit")

    hide_actions = %w[
Severity: Minor
Found in app/helpers/application_helper.rb - About 1 hr to fix

Method qs_show_user_input_checkbox? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def qs_show_user_input_checkbox?
    return true if @edit[:expression_method]
    return false unless @edit[:adv_search_open] # Only allow user input for advanced searches
    return false unless QS_VALID_USER_INPUT_OPERATORS.include?(@edit[@expkey][:exp_key])
    val = (@edit[@expkey][:exp_typ] == "field" && # Field atoms with certain field types return true
Severity: Minor
Found in app/helpers/application_helper.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

Consider simplifying this complex logical expression.
Open

    if @edit && @edit[:expression] &&
       (default_search?(search.name) && expression_selected_nil_or_id(search.id) ||
        (@edit[:expression][:selected].nil? && search.id.to_i.zero? ||
         expression_selected_id_or_name(:name, search.name)))
      'active'
Severity: Major
Found in app/helpers/application_helper.rb - About 1 hr to fix

Method db_to_controller has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def db_to_controller(db, action = "show")
    action = "x_show" if @explorer
    case db
    when "ActionSet"
      controller = "miq_action"
Severity: Minor
Found in app/helpers/application_helper.rb - About 55 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 record_no_longer_exists? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def record_no_longer_exists?(what, model = nil)
    return false unless what.nil?

    if !@bang || @flash_array.empty?
      # We already added a better flash message in 'identify_record'
Severity: Minor
Found in app/helpers/application_helper.rb - About 55 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 object_types_for_flash_message has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def object_types_for_flash_message(klass, record_ids)
    if klass == VmOrTemplate
      object_ary = klass.where(:id => record_ids).collect { |rec| ui_lookup(:model => model_for_vm(rec).to_s) }
      obj_hash = object_ary.each.with_object(Hash.new(0)) { |obj, h| h[obj] += 1 }
      obj_hash.collect { |k, v| v == 1 ? k : k.pluralize }.sort.to_sentence
Severity: Minor
Found in app/helpers/application_helper.rb - About 55 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 def_searches_active_filter? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def def_searches_active_filter?(search)
    if @edit && @edit[:expression] &&
       ((default_search?(search.name) || no_default_search?(search.id)) && expression_selected_nil_or_id(search.id) ||
        (@edit[:expression][:selected] && @edit[:expression][:selected][:id].zero? && search.id.to_i.zero? ||
         expression_selected_id_or_name(:name, search.name)))
Severity: Minor
Found in app/helpers/application_helper.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

Method javascript_for_miq_button_visibility has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def javascript_for_miq_button_visibility(display, prefix = nil)
    if prefix
      "miqButtons('#{display ? 'show' : 'hide'}', '#{prefix}');".html_safe
    else
      "miqButtons('#{display ? 'show' : 'hide'}');".html_safe
Severity: Minor
Found in app/helpers/application_helper.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

Avoid deeply nested control flow statements.
Open

        elsif view.db == "MiqServer" &&
              %w[ops report].include?(request.parameters[:controller])
          return "/" + request.parameters[:controller] + "/tree_select/?id=" + TREE_WITH_TAB[active_tab]
        elsif %w[ScanItemSet
                 MiqSchedule
Severity: Major
Found in app/helpers/application_helper.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

          if @tagging
            return false # when tagging Users, Groups, Roles and Tenants, the table is non-clickable
          else
            return "/" + request.parameters[:controller] + "/tree_select/?id=" + x_node.split("-")[1]
          end
Severity: Major
Found in app/helpers/application_helper.rb - About 45 mins to fix

Consider simplifying this complex logical expression.
Open

    if (@lastaction != "show" || (@lastaction == "show" && @display != "main")) &&
       @record &&
       (@record.respond_to?('name') && !@record.name.nil?)
      return true
    else
Severity: Major
Found in app/helpers/application_helper.rb - About 40 mins to fix

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

  def role_allows?(**options)
    features = Array(options[:feature])

    if features.blank?
      $log.debug("Auth failed - no feature was specified (required)")
Severity: Minor
Found in app/helpers/application_helper.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 miq_tab_content has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def miq_tab_content(id, active = nil, options = {}, &_block)
    lazy = options[:lazy] && active != id

    classname = %w[tab-pane]
    classname << options[:class] if options[:class]
Severity: Minor
Found in app/helpers/application_helper.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

Avoid too many return statements within this method.
Open

          return url_for_only_path(:action => action) + "/" # In explorer, don't jump to other controllers
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

          return url_for_only_path(:controller => "vm_or_template", :action => "show") + "/"
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return ems_networks_path
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

          return "/" + request.parameters[:controller] + "/tree_select/?id=" + TREE_WITH_TAB[active_tab]
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

    return false if @layout == "configuration" && @tabform != "ui_4"
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

          return "/#{params[:controller]}/tree_select/?id=#{TreeBuilder.get_prefix_for_model(view.db)}"
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return "/" + request.parameters[:controller] + "/tree_select/?id=" + x_node.split("-")[1]
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

          return "/" + request.parameters[:controller] + "/tree_select?id=" + suffix
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return url_for_only_path(:controller => 'restful_redirect', :model => 'ExtManagementSystem') if controller == 'ext_management_system'
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return url_for_only_path(:action => action, :id => params[:id]) + "?display=generic_objects&generic_object_id="
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

          return url_for_only_path(:controller => controller, :action => "show") + "/"
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return url_for_only_path(:controller => controller, :action => action, :id => nil) + "/"
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

      return url_for_only_path(:controller => parent.kind_of?(VmOrTemplate) && !@explorer ? parent.class.base_model.to_s.underscore : request.parameters["controller"],
                               :action     => association,
                               :id         => parent.id) + "?#{@explorer ? "x_show" : "show"}="
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return ems_storages_path
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return false # when tagging Users, Groups, Roles and Tenants, the table is non-clickable
Severity: Major
Found in app/helpers/application_helper.rb - About 30 mins to fix

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

  def show_taskbar_in_header?
    return false if @explorer
    return false if controller.action_name.end_with?("tagging_edit")

    hide_actions = %w[
Severity: Minor
Found in app/helpers/application_helper.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 model_to_report_data has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def model_to_report_data
    # @report_data_additional_options[:model] is most important, others can be removed
    return @report_data_additional_options[:model] if @report_data_additional_options && @report_data_additional_options[:model]
    return @display.classify if @display && @display != "main"
    return params[:db].classify if params[:db]
Severity: Minor
Found in app/helpers/application_helper.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 my_searches_active_filter? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def my_searches_active_filter?(search)
    if @edit && @edit[:expression] &&
       (default_search?(search.name) && expression_selected_nil_or_id(search.id) ||
        (@edit[:expression][:selected].nil? && search.id.to_i.zero? ||
         expression_selected_id_or_name(:name, search.name)))
Severity: Minor
Found in app/helpers/application_helper.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 model_for_vm has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def model_for_vm(record)
    raise _("Record is not VmOrTemplate class") unless record.kind_of?(VmOrTemplate)
    if record.kind_of?(ManageIQ::Providers::CloudManager::Vm)
      ManageIQ::Providers::CloudManager::Vm
    elsif record.kind_of?(ManageIQ::Providers::InfraManager::Vm)
Severity: Minor
Found in app/helpers/application_helper.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 process_show_list_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def process_show_list_options(options, curr_model = nil)
    @report_data_additional_options = ApplicationController::ReportDataAdditionalOptions.from_options(options)
    @report_data_additional_options.with_quadicon_options(
      :embedded   => @embedded,
      :showlinks  => @showlinks,
Severity: Minor
Found in app/helpers/application_helper.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

Avoid more than 3 levels of block nesting.
Open

          if params[:tab_id] == "saved_reports" || params[:pressed] == "miq_report_run" || params[:action] == "reload"
            suffix = x_node
          end
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

          if @tagging
            return false # when tagging Users, Groups, Roles and Tenants, the table is non-clickable
          else
            return "/" + request.parameters[:controller] + "/tree_select/?id=" + x_node.split("-")[1]
          end
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Use #key? instead of #keys.include?.
Open

      VALID_PERF_PARENTS.keys.include?(@perf_options[:parent])
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Check block argument explicitly instead of using block_given?.
Open

    if block_given?
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Use :name instead of 'name'.
Open

       (@record.respond_to?('name') && !@record.name.nil?)
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

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

    if !@flash_array && !@refresh_partial # if no button handler ran, show not implemented msg
      add_flash(_("Button not yet implemented"), :error)
      @refresh_partial = "layouts/flash_msg"
      @refresh_div = "flash_msg_div"
    elsif @flash_array && @lastaction == "show"
Severity: Minor
Found in app/helpers/application_helper.rb and 1 other location - About 20 mins to fix
app/controllers/host_controller.rb on lines 240..248

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 32.

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

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

        (@edit[:expression][:selected].nil? && search.id.to_i.zero? ||
Severity: Minor
Found in app/helpers/application_helper.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

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

    @edit[:expression][:selected].nil? && @edit[:selected].nil? || expression_selected_id_or_name(:id, search_id.to_i)
Severity: Minor
Found in app/helpers/application_helper.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

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

       ((default_search?(search.name) || no_default_search?(search.id)) && expression_selected_nil_or_id(search.id) ||
Severity: Minor
Found in app/helpers/application_helper.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

Duplicate branch body detected.
Open

    when "ManageIQ::Providers::ExternalAutomationManager", "OrchestrationStackOutput", "OrchestrationStackParameter", "OrchestrationStackResource",
        "ManageIQ::Providers::CloudManager::OrchestrationStack",
        "ManageIQ::Providers::CloudManager::CloudDatabase",
        "ManageIQ::Providers::ConfigurationManager",
        "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem",
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Checks that there are no repeated bodies within if/unless, case-when, case-in and rescue constructs.

With IgnoreLiteralBranches: true, branches are not registered as offenses if they return a basic literal value (string, symbol, integer, float, rational, complex, true, false, or nil), or return an array, hash, regexp or range that only contains one of the above basic literal values.

With IgnoreConstantBranches: true, branches are not registered as offenses if they return a constant value.

Example:

# bad
if foo
  do_foo
  do_something_else
elsif bar
  do_foo
  do_something_else
end

# good
if foo || bar
  do_foo
  do_something_else
end

# bad
case x
when foo
  do_foo
when bar
  do_foo
else
  do_something_else
end

# good
case x
when foo, bar
  do_foo
else
  do_something_else
end

# bad
begin
  do_something
rescue FooError
  handle_error
rescue BarError
  handle_error
end

# good
begin
  do_something
rescue FooError, BarError
  handle_error
end

Example: IgnoreLiteralBranches: true

# good
case size
when "small" then 100
when "medium" then 250
when "large" then 1000
else 250
end

Example: IgnoreConstantBranches: true

# good
case size
when "small" then SMALL_SIZE
when "medium" then MEDIUM_SIZE
when "large" then LARGE_SIZE
else MEDIUM_SIZE
end

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

       item.fetch_path(:value).kind_of?(Array) &&
       item[:value].any? { |val| val[:link] }
Severity: Minor
Found in app/helpers/application_helper.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

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

        (@edit[:expression][:selected] && @edit[:expression][:selected][:id].zero? && search.id.to_i.zero? ||
Severity: Minor
Found in app/helpers/application_helper.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

Binary operator && has identical operands.
Open

      (@toolbars['history_tb'] != 'blank_view_tb' && @toolbars['history_tb'] != 'blank_view_tb' && @toolbars['view_tb'] != 'blank_view_tb')
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Checks for places where binary operator has identical operands.

It covers arithmetic operators: -, /, %; comparison operators: ==, ===, =~, >, >=, <, <=; bitwise operators: |, ^, &; boolean operators: &&, || and "spaceship" operator - <=>.

Simple arithmetic operations are allowed by this cop: +, *, **, << and >>. Although these can be rewritten in a different way, it should not be necessary to do so. This does not include operations such as - or / where the result will always be the same (x - x will always be 0; x / x will always be 1), and thus are legitimate offenses.

Safety:

This cop is unsafe as it does not consider side effects when calling methods and thus can generate false positives, for example:

if wr.take_char == '\0' && wr.take_char == '\0'
  # ...
end

Example:

# bad
x / x
x.top >= x.top

if a.x != 0 && a.x != 0
  do_something
end

def child?
  left_child || left_child
end

# good
x + x
1 << 1

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

       @edit && no_default_search?(search.id) &&
       settings_default('0', :default_search, @edit&.dig(@expkey, :exp_model).to_s.to_sym).to_s == '0'
Severity: Minor
Found in app/helpers/application_helper.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

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

       (default_search?(search.name) && expression_selected_nil_or_id(search.id) ||
Severity: Minor
Found in app/helpers/application_helper.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