ManageIQ/manageiq-ui-classic

View on GitHub
app/helpers/application_helper/toolbar_builder.rb

Summary

Maintainability
D
2 days
Test Coverage
A
98%

Class ToolbarBuilder has 35 methods (exceeds 20 allowed). Consider refactoring.
Open

class ApplicationHelper::ToolbarBuilder
  include MiqAeClassHelper
  include RestfulControllerMixin
  include ApplicationHelper::Toolbar::Mixins::CustomButtonToolbarMixin

Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.rb - About 4 hrs to fix

Method build_select_button has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

  def build_select_button(bgi, index)
    bs_children = false
    props = toolbar_button(bgi, :id => bgi[:id], :type => :buttonSelect)
    return nil if props.nil?

Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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 twostate_button_selected is too high. [20/11]
Open

  def twostate_button_selected(id)
    return true if id.starts_with?("view_") && id.ends_with?("textual") # Summary view buttons
    return true if @ght_type && id.starts_with?("view_") && id.ends_with?(@ght_type)  # GHT view buttons on report show
    return true if id.starts_with?("compare_") && id.ends_with?(settings(:views, :compare).to_s)
    return true if id.starts_with?("drift_") && id.ends_with?(settings(:views, :drift).to_s)

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 build_select_button is too high. [14/11]
Open

  def build_select_button(bgi, index)
    bs_children = false
    props = toolbar_button(bgi, :id => bgi[:id], :type => :buttonSelect)
    return nil if props.nil?

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 get_custom_buttons is too high. [13/11]
Open

  def get_custom_buttons(model, record, toolbar_result)
    cbses = CustomButtonSet.find_all_by_class_name(button_class_name(model), service_template_id(record))
    cbses = CustomButtonSet.filter_with_visibility_expression(cbses, record)

    cbses.sort_by { |cbs| cbs.set_data[:group_index] }.collect do |cbs|

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 get_custom_buttons has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  def get_custom_buttons(model, record, toolbar_result)
    cbses = CustomButtonSet.find_all_by_class_name(button_class_name(model), service_template_id(record))
    cbses = CustomButtonSet.filter_with_visibility_expression(cbses, record)

    cbses.sort_by { |cbs| cbs.set_data[:group_index] }.collect do |cbs|
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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 twostate_button_selected has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def twostate_button_selected(id)
    return true if id.starts_with?("view_") && id.ends_with?("textual") # Summary view buttons
    return true if @ght_type && id.starts_with?("view_") && id.ends_with?(@ght_type)  # GHT view buttons on report show
    return true if id.starts_with?("compare_") && id.ends_with?(settings(:views, :compare).to_s)
    return true if id.starts_with?("drift_") && id.ends_with?(settings(:views, :drift).to_s)
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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 create_custom_button has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def create_custom_button(input, model, record)
    button_id = input[:id]
    button_name = input[:name].to_s
    record_id = if cb_send_checked_list
                  'LIST'
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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 get_custom_buttons has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def get_custom_buttons(model, record, toolbar_result)
    cbses = CustomButtonSet.find_all_by_class_name(button_class_name(model), service_template_id(record))
    cbses = CustomButtonSet.filter_with_visibility_expression(cbses, record)

    cbses.sort_by { |cbs| cbs.set_data[:group_index] }.collect do |cbs|
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.rb - About 1 hr to fix

Method build_select_button has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def build_select_button(bgi, index)
    bs_children = false
    props = toolbar_button(bgi, :id => bgi[:id], :type => :buttonSelect)
    return nil if props.nil?

Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.rb - About 1 hr to fix

Method apply_common_props has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def apply_common_props(button, input)
    button.update(
      :color        => input[:color],
      :data         => button.data(input[:data]),
      :hidden       => button[:hidden] || !!input[:hidden],
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.rb - About 1 hr to fix

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

  def custom_button_selects(model, record, toolbar_result)
    get_custom_buttons(model, record, toolbar_result).collect do |group|
      buttons = group[:buttons].collect { |b| create_custom_button(b, model, record) }

      enabled = if cb_send_checked_list
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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 apply_common_props has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def apply_common_props(button, input)
    button.update(
      :color        => input[:color],
      :data         => button.data(input[:data]),
      :hidden       => button[:hidden] || !!input[:hidden],
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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 custom_button_add_related_buttons has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def custom_button_add_related_buttons(model, record, toolbar)
    # For Service, we include buttons for ServiceTemplate.
    # These buttons are added as a single group with multiple buttons
    if record.kind_of?(Service)
      service_buttons = record_to_service_buttons(record)
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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 too many return statements within this method.
Open

    return true if id.starts_with?("comparemode_") && id.ends_with?(settings(:views, :compare_mode).to_s)
Severity: Major
Found in app/helpers/application_helper/toolbar_builder.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

    return true if id.starts_with?("driftmode_") && id.ends_with?(settings(:views, :drift_mode).to_s)
Severity: Major
Found in app/helpers/application_helper/toolbar_builder.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

    return true if id == "view_dashboard" && @showtype == "dashboard"
Severity: Major
Found in app/helpers/application_helper/toolbar_builder.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

    return true if id == "compare_all"
Severity: Major
Found in app/helpers/application_helper/toolbar_builder.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

    return true if id == "view_summary" && @showtype == "main"
Severity: Major
Found in app/helpers/application_helper/toolbar_builder.rb - About 30 mins to fix

Avoid too many return statements within this method.
Open

    return true if id == "drift_all"
Severity: Major
Found in app/helpers/application_helper/toolbar_builder.rb - About 30 mins to fix

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

  def custom_toolbar_class(toolbar_result)
    record = @record
    if @display == 'generic_objects'
      model = GenericObjectDefinition
      record = GenericObject.find_by(:id => @sb[:rec_id])
Severity: Minor
Found in app/helpers/application_helper/toolbar_builder.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

There are no issues that match your filters.

Category
Status