theforeman/foreman

View on GitHub

Showing 722 of 1,271 total issues

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

  def before_destroy(record)
    klasses.each do |klass, klass_name = klass|
      association = record.association(klass.to_sym)
      association_scope = ActiveRecord::Associations::AssociationScope.scope(association)
      next if association_scope.empty?
Severity: Minor
Found in app/models/concerns/ensure_not_used_by.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 update_interfaces has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def update_interfaces(vm, attrs)
      interfaces = nested_attributes_for :interfaces, attrs
      interfaces.each do |interface|
        vm.destroy_interface(:id => interface[:id]) if interface[:_delete] == '1' && interface[:id]
        if interface[:id].blank?
Severity: Minor
Found in app/models/compute_resources/foreman/model/ovirt.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 crypt_pass has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def crypt_pass(unencrypted_pass, pass_kind)
    return unless unencrypted_pass.present?
    is_actually_encrypted = if operatingsystem.try(:password_hash) == "Base64" || operatingsystem.try(:password_hash) == "Base64-Windows"
                              password_base64_encrypted?
                            elsif PasswordCrypt.crypt_gnu_compatible?
Severity: Minor
Found in app/models/concerns/host_common.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 queue_tftp_destroy has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def queue_tftp_destroy(validate = true, priority = 20, host = self)
    if validate
      return unless (tftp? || tftp6?) && no_errors
      return true if host.jumpstart?
    end
Severity: Minor
Found in app/models/concerns/orchestration/tftp.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

Function TaxonomyDropdown has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

const TaxonomyDropdown = ({ taxonomyType, currentTaxonomy, taxonomies }) => {
  const id = `${taxonomyType}-dropdown`;
  const anyTaxonomyURL = foremanUrl(`/${taxonomyType}s/clear`);
  const manageTaxonomyURL = foremanUrl(`/${taxonomyType}s`);
  const anyTaxonomyText =

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

    def template_kinds(provisioning = nil)
      return TemplateKind.all unless provisioning == 'image'
      cr_id  = compute_resource_id || hostgroup&.compute_resource_id
      cr     = ComputeResource.find_by_id(cr_id)
      images = cr.try(:images)
Severity: Minor
Found in app/models/concerns/hostext/operating_system.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 supports_operating_systems? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def supports_operating_systems?
      if client.respond_to?(:operating_systems)
        unless attrs.key?(:available_operating_systems)
          update_available_operating_systems
          save
Severity: Minor
Found in app/models/compute_resources/foreman/model/ovirt.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 initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(name, options)
      raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
      raise ArgumentError, "Invalid option :engine for menu item '#{name}'" if options[:engine] && !options[:engine].respond_to?(:routes)
      raise ArgumentError, "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash)
      raise ArgumentError, "Cannot set the :parent to be the same as this item" if options[:parent] == name.to_sym
Severity: Minor
Found in app/registries/menu/item.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 remove_old_cache_for_old_record has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def remove_old_cache_for_old_record
    klass = member_type_changed? ? member_type_was.constantize : member_type.constantize
    users = if member_id_changed?
              find_all_affected_users_for(klass.unscoped.find(member_id_was)).flatten
            else
Severity: Minor
Found in app/models/usergroup_member.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 setComputeIP has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def setComputeIP
    attrs = compute_resource.provided_attributes
    if attrs.key?(:ip) || attrs.key?(:ip6)
      logger.info "Waiting for #{name} to become ready"
      compute_resource.vm_ready vm
Severity: Minor
Found in app/models/concerns/orchestration/compute.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 ensure_taxonomies_not_escalated has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def ensure_taxonomies_not_escalated
    Taxonomy.types.each do |taxonomy|
      assoc_base = taxonomy.to_s.downcase
      assoc = assoc_base.pluralize
      key = assoc_base + '_ids'
Severity: Minor
Found in app/models/concerns/taxonomix.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 to_label has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def to_label(options = {})
      handle_options(options)

      if host && !host.enabled
        N_("Alerts disabled")
Severity: Minor
Found in app/models/host_status/configuration_status.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 authorized_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def authorized_for(options)
    action          = options.delete(:auth_action) || options[:action]
    object          = options.delete(:auth_object)
    user            = User.current
    controller      = options[:controller] || params[:controller]
Severity: Minor
Found in app/helpers/authorize_helper.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 icon has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def icon(record, opts = {})
    return "" if record.blank? || record.name.blank?
    size = opts[:size] ||= '16x16'
    name = case record.name.downcase
           when /fedora|fcos|coreos/i
Severity: Minor
Found in app/helpers/operatingsystems_helper.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

Avoid deeply nested control flow statements.
Open

          File.delete(old_avatar) if File.exist?(old_avatar)
Severity: Major
Found in app/models/user.rb - About 45 mins to fix

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

        def self.terminate_connection(url = nil)
          if url
            local_names = ["libvirt_connection_#{url}"]
          else
            local_names = Thread.current.keys
    Severity: Minor
    Found in app/models/compute_resources/foreman/model/libvirt.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 value= has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def value=(v)
        v = v.to_yaml unless v.nil?
        # the has_attribute is for enabling DB migrations on older versions
        if setting_definition&.encrypted?
          # Don't re-write the attribute if the current encrypted value is identical to the new one
    Severity: Minor
    Found in app/models/setting.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 get_interface_scope has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_interface_scope(name, attributes, base = interfaces)
          case interface_class(name).to_s
            # we search bonds based on identifiers, e.g. ubuntu sets random MAC after each reboot se we can't
            # rely on mac
            when 'Nic::Bond', 'Nic::Bridge'
    Severity: Minor
    Found in app/models/host/base.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 multiple_selects has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def multiple_selects(f, attr, associations, selected_ids, options = {}, html_options = {})
    Severity: Minor
    Found in app/helpers/form_helper.rb - About 45 mins to fix
      Severity
      Category
      Status
      Source
      Language