theforeman/foreman

View on GitHub
app/models/host/managed.rb

Summary

Maintainability
F
4 days
Test Coverage

Class Managed has 97 methods (exceeds 20 allowed). Consider refactoring.
Open

class Host::Managed < Host::Base
  # audit the changes to this model
  audited :except => [:last_report, :last_compile, :lookup_value_matcher, :global_status]
  has_associated_audits
  # redefine audits relation because of the type change (by default the relation will look for auditable_type = 'Host::Managed')
Severity: Major
Found in app/models/host/managed.rb - About 1 day to fix

    File managed.rb has 774 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Host::Managed < Host::Base
      # audit the changes to this model
      audited :except => [:last_report, :last_compile, :lookup_value_matcher, :global_status]
      has_associated_audits
      # redefine audits relation because of the type change (by default the relation will look for auditable_type = 'Host::Managed')
    Severity: Major
    Found in app/models/host/managed.rb - About 1 day to fix

      Method ensure_associations has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def ensure_associations
          status = true
          if managed? && os && !image_build?
            %w{ptable medium architecture}.each do |e|
              value = send(e.to_sym)
      Severity: Minor
      Found in app/models/host/managed.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 apply_inherited_attributes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def apply_inherited_attributes(attributes, initialized = true)
          return nil unless attributes
      
          attributes = hash_clone(attributes).with_indifferent_access
      
      
      Severity: Minor
      Found in app/models/host/managed.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 set_ip_address has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_ip_address
          return unless new_record? || managed?
          interfaces.select { |nic| nic.managed }.each do |nic|
            nic.ip  = nic.subnet.unused_ip(mac).suggest_ip if nic.subnet.present? && nic.ip.blank?
            nic.ip6 = nic.subnet6.unused_ip(mac).suggest_ip if nic.subnet6.present? && nic.ip6.blank?
      Severity: Minor
      Found in app/models/host/managed.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 trigger_nic_orchestration has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def trigger_nic_orchestration
          primary_interface.valid? if primary_interface && !primary_interface.changed?
          unless provision_interface.nil?
            return if primary_interface == provision_interface
            provision_interface.valid? if provision_interface && !provision_interface.changed?
      Severity: Minor
      Found in app/models/host/managed.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 attributes_to_import_from_facts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def attributes_to_import_from_facts
          attrs = [:architecture]
          if Setting[:update_hostgroup_from_facts]
            attrs << :hostgroup
          end
      Severity: Minor
      Found in app/models/host/managed.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

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

        def recreate_config(only = nil)
          result = {}
      
          Nic::Managed.rebuild_methods_for(only).map do |method, pretty_name|
            interfaces.map do |interface|
      Severity: Minor
      Found in app/models/host/managed.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

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

        def inherited_attributes
          inherited_attrs = %w{domain_id operatingsystem_id architecture_id compute_resource_id}
          inherited_attrs << "subnet_id" unless compute_provides?(:ip)
          inherited_attrs << "subnet6_id" unless compute_provides?(:ip6)
          inherited_attrs.concat(%w{medium_id ptable_id pxe_loader}) unless image_build?
      Severity: Minor
      Found in app/models/host/managed.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 send_built_notification has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def send_built_notification
          recipients = owner ? owner.recipients_for(:host_built) : []
          MailNotification[:host_built].deliver(self, :users => recipients) if recipients.present?
        rescue SocketError, Net::SMTPError => e
          Foreman::Logging.exception("Host has been created. Failed to send email", e)
      Severity: Minor
      Found in app/models/host/managed.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