theforeman/foreman

View on GitHub
app/models/concerns/orchestration/dhcp.rb

Summary

Maintainability
C
1 day
Test Coverage

Method dhcp_attrs has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

  def dhcp_attrs(record_mac)
    raise ::Foreman::Exception.new(N_("DHCP not supported for this NIC")) unless dhcp?

    dhcp_attr = {
      :name => dhcp_record_name(record_mac),
Severity: Minor
Found in app/models/concerns/orchestration/dhcp.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

Consider simplifying this complex logical expression.
Open

    return true if ((old.ip != ip) ||
      (old.hostname != hostname) ||
      provision_mac_addresses_changed? ||
      (old.subnet != subnet) ||
      (old&.operatingsystem&.boot_filename(old.host) != operatingsystem&.boot_filename(host)) ||
Severity: Critical
Found in app/models/concerns/orchestration/dhcp.rb - About 2 hrs to fix

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

      def dhcp_update_required?
        # IP Address / name changed, or 'rebuild' action is triggered and DHCP record on the smart proxy is not present/identical.
        return true if ((old.ip != ip) ||
          (old.hostname != hostname) ||
          provision_mac_addresses_changed? ||
    Severity: Minor
    Found in app/models/concerns/orchestration/dhcp.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

    Consider simplifying this complex logical expression.
    Open

          if !old.build? || (old.medium != medium || old.arch != arch) ||
              (os && old.os && (old.os.name != os.name || old.os != os))
            return true
          end
    Severity: Major
    Found in app/models/concerns/orchestration/dhcp.rb - About 1 hr to fix

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

        def queue_dhcp
          return log_orchestration_errors unless (dhcp? || old&.dhcp?) && orchestration_errors?
          queue_remove_dhcp_conflicts
          new_record? ? queue_dhcp_create : queue_dhcp_update
        end
      Severity: Minor
      Found in app/models/concerns/orchestration/dhcp.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 dhcp_conflict_detected? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def dhcp_conflict_detected?
          # we can't do any dhcp based validations when our MAC address is defined afterwards (e.g. in vm creation)
          return false if mac.blank? || hostname.blank?
          return false unless dhcp?
      
      
      Severity: Minor
      Found in app/models/concerns/orchestration/dhcp.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