ManageIQ/manageiq-ui-classic

View on GitHub

Showing 18,390 of 18,390 total issues

Cyclomatic complexity for get_reconfig_info is too high. [14/11]
Open

        def get_reconfig_info(reconfigure_ids)
          @reconfigureitems = Vm.find(reconfigure_ids).sort_by(&:name)
          # set memory to nil if multiple items were selected with different mem_cpu values
          memory = @reconfigureitems.first.mem_cpu
          memory = nil unless @reconfigureitems.all? { |vm| vm.mem_cpu == memory }

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

  def handle_bottom_cell(presenter)
    if allowed(@sb[:action]) && (@pages || @in_a_form)
      if @pages
        presenter.hide(:form_buttons_div)
      elsif @in_a_form && @sb[:action]

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

  def schedule_form_field_changed
    assert_privileges(@edit && @edit[:rpt_id] ? "miq_report_schedule_edit" : "miq_report_schedule_add")

    return unless load_edit("schedule_edit__#{params[:id]}", "replace_cell__explorer")
    schedule_get_form_vars

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

  def center_toolbar_filename_explorer
    if %w[vm_cloud vm_infra vm_or_template].include?(@layout)
      center_toolbar_name_vm_or_template
    elsif x_active_tree == :ae_tree
      center_toolbar_filename_automate

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

  def get_all_reps(nodeid = nil)
    # set nodeid from @sb, incase sort was pressed
    nodeid = x_active_tree == :reports_tree ? x_node.split('-').last : x_node.split('-').last.split('_')[0] if nodeid.nil?
    @sb[:miq_report_id] = nodeid
    @record = @miq_report = MiqReport.for_user(current_user).find(@sb[:miq_report_id])

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

  def tree_select
    assert_accordion_and_tree_privileges(x_active_tree)
    params[:miq_grid_checks] = []
    @explorer = true
    @lastaction = "explorer"
Severity: Minor
Found in app/controllers/vm_common.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 widget_form_field_changed is too high. [14/11]
Open

  def widget_form_field_changed
    assert_privileges(feature_for_widget_action)

    return unless load_edit("widget_edit__#{params[:id]}", "replace_cell__explorer")
    widget_get_form_vars

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

  def reconfigure_form_data(vm = @reconfigitems.first)
    {
      :recordId  => @reconfigitems.collect(&:id),
      :requestId => @request_id || 'new',
      :roles     => {
Severity: Minor
Found in app/helpers/vm_infra_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

Function getInitialValues has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const getInitialValues = (recId, setState) => {
  if (recId) {
    API.get(`/api/custom_buttons/${recId}?attributes=resource_action,uri_attributes`)
      .then((initialValues) => {
        if (initialValues.options.button_type === 'ansible_playbook') {

Function setNetworkFormSubmit has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const setNetworkFormSubmit = (data, setData, formData, roles, renderData) => {
  if (data.form.action === 'add') {
    // code for add function
    const id = `network${data.dataTable.networkAdapters.length}`;
    const networkData = {
Severity: Minor
Found in app/javascript/components/reconfigure-vm-form/helpers/network.js - About 2 hrs to fix

Function render has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  render() {
    // eslint-disable-next-line consistent-return
    const renderSpinner = (spinnerOn) => {
      if (spinnerOn) {
        return (
Severity: Minor
Found in app/javascript/components/remove-generic-item-modal.jsx - About 2 hrs to fix

Function onClick has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const onClick = (button) => {
  let buttonUrl;

  if (button.confirm && !window.confirm(button.confirm)) {
    // No handling unless confirmed.
Severity: Minor
Found in app/javascript/components/miq-toolbar.jsx - About 2 hrs to fix

Method layout_uses_listnav? has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def layout_uses_listnav?
    return false if action_name == "show"
    return false if show_list_with_no_provider?

    return false if show_list_ansible?
Severity: Minor
Found in app/helpers/application_helper/page_layouts.rb - About 2 hrs to fix

Method catalog_basic_information has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def catalog_basic_information(record, sb_params, tenants_tree)
    prov_types = catalog_provision_types
    prov_data = [prov_types[:template], prov_types[:ovf]].include?(record.prov_type) && (catalog_provision?(record, :playbook) || catalog_provision?(record, :terraform_template)) ? provisioning : nil
    data = {:title => _('Basic Information'), :mode => "miq_catalog_basic_information"}
    rows = []
Severity: Minor
Found in app/helpers/catalog_helper.rb - About 2 hrs to fix

Method launch_external_logging has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def launch_external_logging
      assert_privileges('ems_container_launch_external_logging')
      record = self.class.model.find(params[:id])
      ems = record.ext_management_system
      route_name = ems.external_logging_route_name
Severity: Minor
Found in app/controllers/mixins/containers_external_logging_support_mixin.rb - About 2 hrs to fix

Method view_to_hash has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def view_to_hash(view, fetch_data = false)
    root = {:head => [], :rows => []}

    has_checkbox = !@embedded && !@no_checkboxes

Severity: Minor
Found in app/controllers/application_controller.rb - About 2 hrs to fix

Method db_get_node_info has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def db_get_node_info
    model, rec_id, _ = TreeBuilder.extract_node_model_and_id(x_node)
    @sb[:nodes] = x_node.split('-')
    if @sb[:nodes].length == 1
      @default_ws = MiqWidgetSet.where_unique_on("default").where(:read_only => true).first
Severity: Minor
Found in app/controllers/report_controller/dashboards.rb - About 2 hrs to fix

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

MiqStructuredListConditionalTag.propTypes = {
  row: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.any), PropTypes.shape({})]).isRequired,
  clickEvents: PropTypes.bool.isRequired,
  onClick: PropTypes.func,
};
app/javascript/components/miq-structured-list/miq-structured-list-body/miq-structured-list-body-value.jsx on lines 19..23
app/javascript/components/miq-structured-list/miq-structured-list-body/value-tags/miq-structured-list-link.jsx on lines 44..48

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

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 3 locations. Consider refactoring.
Open

MiqStructuredListBodyValue.propTypes = {
  row: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.any), PropTypes.shape({})]).isRequired,
  clickEvents: PropTypes.bool.isRequired,
  onClick: PropTypes.func,
};
app/javascript/components/miq-structured-list/miq-structured-list-body/value-tags/miq-structured-list-conditional-tag.jsx on lines 16..20
app/javascript/components/miq-structured-list/miq-structured-list-body/value-tags/miq-structured-list-link.jsx on lines 44..48

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

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

Severity
Category
Status
Source
Language