ManageIQ/manageiq-ui-classic

View on GitHub

Showing 18,390 of 18,390 total issues

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

const getRoles = (setState) => API.get('/api/roles?expand=resources&attributes=name')
  .then((response) => {
    const roles = [];
    response.resources.forEach((role) => {
      roles.push({ label: role.name, value: role.name });
app/javascript/components/generic-objects-form/custom-button-form/helper.js on lines 17..27

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

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

ManageIQ.angular.app.directive('greaterThanZero', function() {
  return {
    require: 'ngModel',
    link: function(_scope, _elem, _attrs, ctrl) {
      ctrl.$validators.greaterThanZero = function(viewValue) {
Severity: Major
Found in app/javascript/oldjs/directives/greater_than_zero.js and 1 other location - About 3 hrs to fix
app/javascript/oldjs/directives/greater_or_zero.js on lines 1..17

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

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

const getServiceDialogs = (setState) => API.get('/api/service_dialogs?expand=resources&attributes=label')
  .then((response) => {
    const serviceDialogs = [];
    response.resources.forEach((dialog) => {
      serviceDialogs.push({ label: dialog.label, value: dialog.id });
app/javascript/components/generic-objects-form/custom-button-form/helper.js on lines 5..15

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

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

File toolbar_chooser.rb has 477 lines of code (exceeds 400 allowed). Consider refactoring.
Open

class ApplicationHelper::ToolbarChooser
  include RestfulControllerMixin

  # Return a blank tb if a placeholder is needed for AJAX explorer screens, return nil if no center toolbar to be shown
  def center_toolbar_filename
Severity: Minor
Found in app/helpers/application_helper/toolbar_chooser.rb - About 3 hrs to fix

Method perf_gen_charts has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_gen_charts(rpt, perf_options, parent = false)
    model_title = parent ? "Parent-#{perf_options[:parent]}" : perf_options[:model]
    charts = []
    chart_data = []
    case perf_options[:typ]
Severity: Major
Found in app/controllers/application_controller/performance.rb - About 3 hrs to fix

Method perf_util_daily_gen_data has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def perf_util_daily_gen_data(_refresh = nil)
    @perf_record ||= @record
    @sb[:summary] = nil # Clear out existing summary report
    @sb[:trend_charts] = nil # Clear out the charts to be generated

Severity: Major
Found in app/controllers/application_controller/performance.rb - About 3 hrs to fix

Method prepare_data_for_compare_or_drift_report has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def prepare_data_for_compare_or_drift_report(mode, csv)
    sb_key = mode == :compare ? :miq_temp_params : :miq_drift_params

    # Collect the data from the @compare object
    @data = []
Severity: Major
Found in app/controllers/application_controller/compare.rb - About 3 hrs to fix

Method button has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def button
    @edit = session[:edit] # Restore @edit for adv search box
    params[:display] = @display if %w[vms storages].include?(@display) # Were we displaying vms/storages

    if params[:pressed].starts_with?("vm_", # Handle buttons from sub-items screen
Severity: Major
Found in app/controllers/host_controller.rb - About 3 hrs to fix

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

                "ManageIQ::Providers::AnsibleTower::AutomationManager::ScmCredential": {
                    "label": "Scm",
                    "type": "scm",
                    "attributes": {
                        "userid": {
Severity: Major
Found in app/javascript/spec/ansible-edit-catalog-form/mockdata.js and 1 other location - About 3 hrs to fix
app/javascript/spec/ansible-edit-catalog-form/mockdata.js on lines 3295..3321

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

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

                "ManageIQ::Providers::Awx::AutomationManager::ScmCredential": {
                    "label": "Scm",
                    "type": "scm",
                    "attributes": {
                        "userid": {
Severity: Major
Found in app/javascript/spec/ansible-edit-catalog-form/mockdata.js and 1 other location - About 3 hrs to fix
app/javascript/spec/ansible-edit-catalog-form/mockdata.js on lines 3619..3645

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

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

Cyclomatic complexity for action_valid_record? is too high. [29/11]
Open

  def action_valid_record?(rec)
    edit = @edit[:new]
    options = edit[:options]
    add_flash(_("Description is required"), :error) if edit[:description].blank?
    add_flash(_("Action Type must be selected"), :error) if edit[:action_type].blank?

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

  def fields_get_form_vars
    @ae_class = MiqAeClass.find_by(:id => @edit[:ae_class_id])
    @in_a_form = true
    @in_a_form_fields = true
    if params[:item].blank? && !%w[accept save].include?(params[:button]) && params["action"] != "field_delete"

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

  def edit_reports
    @edit[:selected_reports] = []
    current_group_id = current_user.current_group.try(:id).to_i
    id = session[:node_selected].split('__')
    @selected = id[1].split(':')

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

  def pre_prov
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      flash_to_session(_("Add of new %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]})
      @explorer = session[:edit][:explorer] || false
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 3 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

Method prov_edit has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def prov_edit
    assert_privileges("miq_request_edit")
    if params[:button] == "cancel"
      req = MiqRequest.find(session[:edit][:req_id]) if session[:edit] && session[:edit][:req_id]
      flash_to_session(
Severity: Minor
Found in app/controllers/application_controller/miq_request_methods.rb - About 3 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

Method policy_field_changed has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def policy_field_changed
    return unless load_edit("miq_policy_edit__#{params[:id]}")

    case @edit[:typ]
    when "events"
Severity: Minor
Found in app/controllers/miq_policy_controller/policies.rb - About 3 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

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

  def action_valid_record?(rec)
    edit = @edit[:new]
    options = edit[:options]
    add_flash(_("Description is required"), :error) if edit[:description].blank?
    add_flash(_("Action Type must be selected"), :error) if edit[:action_type].blank?
Severity: Minor
Found in app/controllers/miq_action_controller.rb - About 3 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

Method send_button_changes has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    def send_button_changes
      if @edit
        @changed = (@edit[:new] != @edit[:current])
      elsif @assign
        @changed = (@assign[:new] != @assign[:current])
Severity: Minor
Found in app/controllers/mixins/policy_mixin.rb - About 3 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

Method get_node_info_handle_leaf_node has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def get_node_info_handle_leaf_node(id)
    show_record(id)
    if @record.atomic? && need_prov_dialogs?(@record.prov_type)
      @miq_request = MiqRequest.find_by(:id => @record.service_resources[0].resource_id) if @record.service_resources[0]&.resource_id
      if @miq_request
Severity: Minor
Found in app/controllers/catalog_controller.rb - About 3 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

Method widget_edit has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def widget_edit
    assert_privileges("widget_edit")

    case params[:button]
    when "cancel"
Severity: Minor
Found in app/controllers/report_controller/widgets.rb - About 3 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

Severity
Category
Status
Source
Language