ManageIQ/manageiq-ui-classic

View on GitHub
app/controllers/miq_ae_tools_controller.rb

Summary

Maintainability
D
2 days
Test Coverage
D
68%

Class MiqAeToolsController has 33 methods (exceeds 20 allowed). Consider refactoring.
Open

class MiqAeToolsController < ApplicationController
  include Mixins::BreadcrumbsMixin
  before_action :check_privileges
  before_action :get_session_data
  after_action :cleanup_action
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.rb - About 4 hrs to fix

File miq_ae_tools_controller.rb has 415 lines of code (exceeds 400 allowed). Consider refactoring.
Open

class MiqAeToolsController < ApplicationController
  include Mixins::BreadcrumbsMixin
  before_action :check_privileges
  before_action :get_session_data
  after_action :cleanup_action
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.rb - About 2 hrs to fix

Method get_form_vars has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def get_form_vars
    if params.key?(:starting_object)
      @resolve[:new][:starting_object] = params[:starting_object]
      @resolve[:new][:instance_name] = nil
    end
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.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 import_automate_datastore has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  def import_automate_datastore
    assert_privileges('miq_ae_class_import_export')
    if params[:selected_namespaces].present?
      selected_namespaces = determine_all_included_namespaces(params[:selected_namespaces])
      import_file_upload = ImportFileUpload.where(:id => params[:import_file_upload_id]).first
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.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 form_field_changed has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  def form_field_changed
    assert_privileges('miq_ae_class_simulation')
    get_form_vars
    render :update do |page|
      page << javascript_prologue
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.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 import_automate_datastore has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def import_automate_datastore
    assert_privileges('miq_ae_class_import_export')
    if params[:selected_namespaces].present?
      selected_namespaces = determine_all_included_namespaces(params[:selected_namespaces])
      import_file_upload = ImportFileUpload.where(:id => params[:import_file_upload_id]).first
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.rb - About 1 hr to fix

Method check_git_task has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def check_git_task
    assert_privileges('miq_ae_class_import_export')
    task = MiqTask.find(params[:task_id])
    json = if task.state != MiqTask::STATE_FINISHED
             {:state => task.state}
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.rb - About 1 hr to fix

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

  def retrieve_git_datastore
    assert_privileges('miq_ae_class_import_export')
    git_url = params[:git_url]

    if git_url.blank?
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.rb - About 1 hr to fix

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

  def check_git_task
    assert_privileges('miq_ae_class_import_export')
    task = MiqTask.find(params[:task_id])
    json = if task.state != MiqTask::STATE_FINISHED
             {:state => task.state}
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.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 valid_resolve_object? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def valid_resolve_object?
    add_flash(_("Starting Class must be selected"), :error) if @resolve[:new][:starting_object].blank?
    if @resolve[:new][:instance_name].blank? && @resolve[:new][:other_name].blank?
      add_flash(_("Starting Process is required"), :error)
    end
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.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

Consider simplifying this complex logical expression.
Open

      if params.key?(:instance_name) || params.key?(:starting_object) ||
         params.key?(:target_class) || params.key?(:target_id) ||
         params.key?(:other_name) || params.key?(:target_attr_name)
        unless params.key?(:other_name) || params.key?(:target_attr_name)
          page.replace("resolve_form_div", :partial => "resolve_form")
Severity: Major
Found in app/controllers/miq_ae_tools_controller.rb - About 40 mins to fix

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

  def reset_datastore
    assert_privileges('miq_ae_class_import_export')
    unless params[:task_id]                       # First time thru, kick off the report generate task
      initiate_wait_for_task(:task_id => MiqAutomate.async_datastore_reset)
      return
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.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

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

    ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
      f = ("attribute_" + (i + 1).to_s)
      v = ("value_" + (i + 1).to_s)
      @resolve[:new][:attrs][i][0] = params[f] if params[f.to_sym]
      @resolve[:new][:attrs][i][1] = params[v] if params[v.to_sym]
Severity: Major
Found in app/controllers/miq_ae_tools_controller.rb and 2 other locations - About 1 hr to fix
app/controllers/application_controller/buttons.rb on lines 113..117
app/controllers/miq_action_controller.rb on lines 76..80

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

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

      add_flash(_("%{val} missing for %{field}") % {:val => f.titleize, :field => v.titleize}, :error) if @resolve[:new][:attrs][i][0].blank? && @resolve[:new][:attrs][i][1].present?
      add_flash(_("%{val} missing for %{field}") % {:val => v.titleize, :field => f.titleize}, :error) if @resolve[:new][:attrs][i][0].present? && @resolve[:new][:attrs][i][1].blank?
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.rb and 1 other location - About 25 mins to fix
app/controllers/miq_ae_tools_controller.rb on lines 425..426

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

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

      add_flash(_("%{val} missing for %{field}") % {:val => v.titleize, :field => f.titleize}, :error) if @resolve[:new][:attrs][i][0].present? && @resolve[:new][:attrs][i][1].blank?
    end
Severity: Minor
Found in app/controllers/miq_ae_tools_controller.rb and 1 other location - About 25 mins to fix
app/controllers/miq_ae_tools_controller.rb on lines 424..425

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

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

There are no issues that match your filters.

Category
Status