theforeman/foreman

View on GitHub
app/controllers/hosts_controller.rb

Summary

Maintainability
F
5 days
Test Coverage

File hosts_controller.rb has 796 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class HostsController < ApplicationController
  include Foreman::Controller::ActionPermissionDsl
  include ScopesPerAction
  include Foreman::Controller::HostDetails
  include Foreman::Controller::AutoCompleteSearch
Severity: Major
Found in app/controllers/hosts_controller.rb - About 1 day to fix

    Class HostsController has 83 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class HostsController < ApplicationController
      include Foreman::Controller::ActionPermissionDsl
      include ScopesPerAction
      include Foreman::Controller::HostDetails
      include Foreman::Controller::AutoCompleteSearch
    Severity: Major
    Found in app/controllers/hosts_controller.rb - About 1 day to fix

      Method update_multiple_parameters has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def update_multiple_parameters
          if params[:name].empty?
            warning _("No parameters were allocated to the selected hosts, can't mass assign")
            redirect_to hosts_path
            return
      Severity: Minor
      Found in app/controllers/hosts_controller.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

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

        def setBuild
          forward_url_options
          if @host.setBuild
            if (params[:host] && params[:host][:build] == '1')
              begin
      Severity: Minor
      Found in app/controllers/hosts_controller.rb - About 2 hrs to fix

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

          def setBuild
            forward_url_options
            if @host.setBuild
              if (params[:host] && params[:host][:build] == '1')
                begin
        Severity: Minor
        Found in app/controllers/hosts_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 submit_multiple_build has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def submit_multiple_build
            reboot = params[:host][:build] == '1' || false
        
            missed_hosts = @hosts.select do |host|
              success = true
        Severity: Minor
        Found in app/controllers/hosts_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 find_multiple has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          def find_multiple
            # Lets search by name or id and make sure one of them exists first
            if params.key?(:host_names) || params.key?(:host_ids) || multiple_with_filter?
              @hosts = resource_base.search_for(params[:search]) if multiple_with_filter?
              @hosts ||= resource_base.merge(Host.where(id: params[:host_ids]).or(Host.where(name: params[:host_names])))
        Severity: Minor
        Found in app/controllers/hosts_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 compute_resource_selected has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def compute_resource_selected
            return not_found unless params[:host]
            Taxonomy.as_taxonomy @organization, @location do
              refresh_host
              compute_resource = ComputeResource.authorized(:view_compute_resources).find_by_id(@host.compute_resource_id) if @host.compute_resource_id
        Severity: Minor
        Found in app/controllers/hosts_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 submit_rebuild_config has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          def submit_rebuild_config
            all_fails = {}
            @hosts.each do |host|
              result = host.recreate_config
              result.each_pair do |k, v|
        Severity: Minor
        Found in app/controllers/hosts_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 update_multiple_proxy has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def update_multiple_proxy(proxy_type, host_update_method)
            proxy_id = params[:proxy][:proxy_id]
            if proxy_id
              proxy = SmartProxy.find_by_id(proxy_id)
            else
        Severity: Minor
        Found in app/controllers/hosts_controller.rb - About 1 hr to fix

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

            def update_multiple_parameters
              if params[:name].empty?
                warning _("No parameters were allocated to the selected hosts, can't mass assign")
                redirect_to hosts_path
                return
          Severity: Minor
          Found in app/controllers/hosts_controller.rb - About 1 hr to fix

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

              def update_multiple_proxy(proxy_type, host_update_method)
                proxy_id = params[:proxy][:proxy_id]
                if proxy_id
                  proxy = SmartProxy.find_by_id(proxy_id)
                else
            Severity: Minor
            Found in app/controllers/hosts_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 process_hostgroup has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def process_hostgroup
                @hostgroup = Hostgroup.find(params[:host][:hostgroup_id]) if params[:host][:hostgroup_id].to_i > 0
                return head(:not_found) unless @hostgroup
                refresh_host
                @host.attributes = @host.apply_inherited_attributes(host_params) unless @host.new_record?
            Severity: Minor
            Found in app/controllers/hosts_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

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

              def set_host_type
                return unless params[:host] && params[:host][:type]
                type = params[:host].delete(:type) # important, otherwise mass assignment will save the type.
                if type.constantize.new.is_a?(Host::Base)
                  @host      = @host.becomes(type.constantize)
            Severity: Minor
            Found in app/controllers/hosts_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

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

              def process_taxonomy
                return head(:not_found) unless @location || @organization
                refresh_host
                # revert compute resource to "Bare Metal" (nil) if selected
                # compute resource is not included taxonomy
            Severity: Minor
            Found in app/controllers/hosts_controller.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 find_resource has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def find_resource
                if (id = params[:id]).blank?
                  not_found
                  return false
                end
            Severity: Minor
            Found in app/controllers/hosts_controller.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 refresh_host has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def refresh_host
                @host = Host::Base.authorized(:view_hosts, Host).find_by_id(params[:host_id] || params.dig(:host, :id))
                @host ||= Host.new(host_params)
            
                unless @host.is_a?(Host::Managed)
            Severity: Minor
            Found in app/controllers/hosts_controller.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